DerockD
tRPC3y ago
10 replies
Derock

How to set cookies in trpc response?

I have an app dir project that was created using this t3-app PR.

On the client I have a form and I am using the trpc react client:
import { api } from "~/trpc/react";
[...]
  const login = api.auth.login.useMutation({ ... });


and I have the following route defined:
import { cookies } from "next/headers";

  publicProcedure
    .input(...)
    .mutation(async ({ ctx, input }) => {
      [...]

      // somehow set a cookie
      cookies().set("session", session.data.token, {
        httpOnly: true,
      });

      [...]
    }),


This does not set the cookie though -- no Set-Cookie header is in the response.
I have no idea how to access the response manually to add the header in either.
Was this page helpful?