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
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
I see here
https://github.com/trpc/trpc/discussions/997
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...
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.