How to set cookie in ct3 app router?
I tried to use
cookies
form 'next/headers'
and it's not working.6 Replies
Cookies are read only in route handlers you need to use the response object to set them https://nextjs.org/docs/app/building-your-application/routing/route-handlers
Routing: Route Handlers
Create custom request handlers for a given route using the Web's Request and Response APIs.
Thx you for your answer, I just read it, but how do I
return new Response
with trpc?Solution
I found the solution.
1. change
unstable_httpBatchStreamLink
to httpBatchLink
in trpc/react.tsx
and trpc/server.ts
( https://discord.com/channels/966627436387266600/966627439390380064/1165106604128092190 )
2. pass resHeader
to createTRPCContext
function
3. update createTRPCContext
and createInnerTRPCContext
functions ( I'm using cookie: https://www.npmjs.com/package/cookie )
and you can use cookies
in tRPC context, for example: