Sean Cassiere
Sean Cassiere15mo ago

Using Response with the Next App Router

The route handlers in the App Router, only receive the Request object, requiring you to use a Response to set stuff onto the response like status, cookies, etc. Previously, we were able to pipe the req and res into the context. My question is: what's the new practice for returning data AND setting the status (or cookies) when within a tRPC router (that's nested using the fetch adapter) in the new Next App Router?
2 Replies
Sean Cassiere
Sean Cassiere15mo ago
Optionally could something like cookies from next/headers be used here?
Nick
Nick15mo ago
You can still add those to the context if you like, but RPC isn't a HTTP framework, you're not really meant to manipulate the HTTP response at all If you need to set up auth flows, I'd personally recommend not doing them within tRPC, it works best with a dedicated auth server and SDK wrapping it in my experience, and then you use the tokens to auth with the tRPC API
More Posts