backbone
backbone2y ago

tRPC doesn't support redirect

I use tRPC & @trpc/server/adapters/express. procdure.query({ctx: { res }} => { res.redirect('xxx') }) this will stop node process and some errors like: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client. But if I just use expressjs,it does not happen.
3 Replies
Nick
Nick2y ago
You shouldn't do this, tRPC is not a http server, it's an abstraction which can (but doesn't have to) live inside one If you want redirects, do it on the frontend in response to state changes, or use a http server for those endpoints
backbone
backboneOP2y ago
GitHub
Allow to redirect user for an outbound API · trpc/trpc · Discussion...
Something like this works but feels rather hacky, I wondered if there was a better way export const oauth = createRouter().query('/outbound', { input: z.object({platform: platformSc...
backbone
backboneOP2y ago
I will try to solve it like 1. express router + tRPC caller 2. try catch in trpc procedure that redirect It works well using the first method. The NO.2 remains the same error too.