Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SessionToken sometimes missing if the callback isn't specified #12139

Open
ChloeCaronEng opened this issue Oct 29, 2024 · 0 comments
Open

SessionToken sometimes missing if the callback isn't specified #12139

ChloeCaronEng opened this issue Oct 29, 2024 · 0 comments
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@ChloeCaronEng
Copy link

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:

  1. On the top level, I have everything wrapped in the following (note I need a custom basePath):
<SessionProvider basePath="/auth" session={session}></SessionProvider>
  1. I am using useQuery to make a call to my custom NestJS backend and need to pass it the session token in the authorisation headers.
  2. When calling useSession, the sessionToken would only be present sometimes (I am assuming that there must be some caching)
  3. Adding the above forced it to always return the entire session object
    Note: I am using a Resend provider and a PrismaAdapter

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

@ChloeCaronEng ChloeCaronEng added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

1 participant