trpc nextjs and expressjs middleware
I've custom expressjs server with Nextjs + im using internal package for handling OneLogin (OIDC) hooked as express middleware which runs. before the Nextjs handler for custom server. I encounter a problem where I do fire a request api call via trpc query or mutation and the OIDC middleware catches that the request is 401 then trpc throws
TRPCClientError: Unexpected token 'U', "Unauthorized" is not valid JSON
if I change the response of the middleware as a json instead of text something like
Then I get app-index.js:31 TRPCClientError: Unexpected non-whitespace character after JSON at position 14 (line 1 column 15)
with tRPC. What do i need to do to handle the 401 via trpc and be able to redirect the user to login "client side redirect at this point"0 Replies