-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
feat(jwt): allow getToken
in Server Components
#5791
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Note: this PR should have more checks, update documentation, and probably display some warning. But before going further, if I could get some kind of go signal that’d be terrific 😉 |
I actually think if we should just document to let the Both read the session cookie, but I want our APIs to start converging more, cause right now we have UPDATE Testing locally, I think some adjustments are necessary since the default const session = await unstable_getServerSession({
providers: [], // Currently expected, but we could make this optional
callbacks: { session: ({ token }) => token }, // to bypass the default behavior, see below
}) Here is the default next-auth/packages/next-auth/src/core/routes/session.ts Lines 53 to 60 in 58e30a6
And to satisfy TypeScript, maybe modify things a bit so the return type of |
In that case, how could we get the token? Is it possible to get the token from the session? I need the Edit: I think you answered my question 😉 |
Updated the PR to use
I tried something in the PR. Not fully convinced (seems a bit complex, lots of generics, I wonder if a deeper changer in the API wouldn’t be better). But the types are correctly inferred when using At this point I’m keeping the PR for the suggestion, but feel free to close if you don’t want to follow this way 😉 |
9f8d161
to
8eb43f6
Compare
8eb43f6
to
22aa4ac
Compare
What are your thoughts on #5792 as an alternative to this? Could you review that PR? Created an experimental release for testing too: #5792 (comment) (Sorry, I've been working on that PR without realizing you were going that direction too 😬 💚) |
I prefer your solution! Just tested the experimental release by replacing I wonder if the API isn’t starting to get weird though. Encouraging to call an |
Hence unstable. We might change the name before finalizing. My dream is to have |
☕️ Reasoning
In Next.js, with new
app
folder, it might be necessary to callgetToken
from a server component, with no access to the requestreq
.This PR aims to reproduce what was done on #5741 for
unstable_getServerSession
, to allowgetToken
to be called withoutreq
.🧢 Checklist
🎫 Affected issues
Fixes #5754