Using AuthJS, how to get current user in route.ts in NextJS.
Every time, the session is null even though I am logged in, how can I correctly fetch the user session?
5 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
The imports in the auth.ts file with the getSession function
You need to send the token in the fetchQuery https://docs.convex.dev/api/modules/nextjs#fetchquery
like
fetchQuery(api.foo.bar, {}, {token})
Module: nextjs | Convex Developer Hub
Helpers for integrating Convex into Next.js applications using server rendering.
I wonder how we can make this more clear, did you copy this code from somewhere?
I was reading the https://labs.convex.dev/auth documentation, that's why I wasn't really finding anything. Thanks I managed to get it working.
Convex Auth - Convex Auth
Authentication library for your Convex backend