nextauthjs / nextauthjs/next-auth
SessionToken sometimes missing if the callback isn't specified
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
What is the improvement or update you wish to see?
I was trying to fetch the session client side to get the sessionToken. The sessionToken would only sometimes be available in the session (e.g. when I refresh the page). To resolve this, I needed to add
async session({ session }) {
return session;
},
in the session callbacks to force NextAuth to return the entire session each time. If this is the intended behaviour, it would be good to include this in the documentation.
Is there any context that might help us understand?
My setup:
- On the top level, I have everything wrapped in the following (note I need a custom basePath):
<SessionProvider basePath="/auth" session={session}></SessionProvider>
- I am using
useQueryto make a call to my custom NestJS backend and need to pass it the session token in the authorisation headers. - When calling
useSession, the sessionToken would only be present sometimes (I am assuming that there must be some caching) - Adding the above forced it to always return the entire session object
Note: I am using aResendprovider and aPrismaAdapter
I don't know if this is the intended behaviour but would be great to include it in the docs if so 🙏
Thank you!
Does the docs page already exist? Please link to it.
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SessionProvider configured with basePath="/auth" and the useSession call, then compare behavior with and without the session callback shown in the report. Verify whether sessionToken is intentionally omitted or intermittently unavailable, and document the confirmed callback or configuration behavior if that is the intended result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, react, typescript
- Domain
- authentication, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100