Next-auth session not being fetched in tRPC context
Next-auth session not being fetched in tRPC context
6 Replies
I have got both next-auth and tRPC setup in my next.js app. When I try to fetch the session outside any tRPC route or middleware, It gets resolved properly. I guess Next-auth is working properly the problem is when I try to fetch a session within a tRPC route or middleware. I get null as a result, the user gets
UNAUTHORIZED
response.
Here's my tRPC setup:
src\pages\api\trpc\[trpc].ts
So the problem happens when I am using a protectedProcedure
. I get this error:
publicProcedure
work fine. I am not sure but I think the context is not being initialized properly or something like that. Tried many ways but still unsolved. Your help would mean a lot to me π
My package.json
Note that I am using the Next.js page router not AppPlease help me out and let me know if any other context required π
Hi! Im getting the same error. To reproduce it just clone the websocket/subscriptions, follow the steps and on the first run the error will appear. I think this is the code where it fails
So maybe next-auth related?
My envinfo is
Hey, this is how I bypassed this issue, although I still get null tokens/sessions when I am not supposed to, it functions overall:
I also jsut downloaded the websockets-starter example and the only error I got (not using the mocked edition) was:
But the functionality was pretty much working no problem.
This is quite strangeπ€¨
very strange indeed... I just don't get it how the websockets-starter is so functional with just the getSession() utility
OS maybe has something to do with this, I am on:
Ubuntu 20.04.6 LTS
In my case, outside of tRPC, next-auth is working just fine. Inside trpc, it's not. IDK why.
in tRPC routes, contexts, the session is always null. Because I get this error from Next-auth
Why would next-auth behave like that inside tRPC