-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Unsure how to get my JWT session token #608
Comments
Hi there, Ah the session: { jwt: true },
callbacks: {
jwt: async (token, user, account, profile, isNewUser) => {
console.log('here');
console.log(token);
console.log(user);
const isSignIn = (user) ? true : false
// Add auth_time to token on signin in
if (isSignIn) { token.auth_time = Math.floor(Date.now() / 1000) }
return Promise.resolve(token)
},
session: async (session, token) => {
console.log('here2');
console.log(token);
console.log(session);
if (!session?.user || !token?.account) {
return session
}
session.user.id = token.account.id
session.accessToken = token.account.accessToken
return session
}
} If you move them, what you are doing should work. :-) The documentation isn't as clear on this as it could be. You can also use the |
Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep ot open. Thanks! |
Hi there! It looks like this issue hasn't had any activity for a while. To keep things tidy, I am going to close this issue for now. If you think your issue is still relevant, just leave a comment and I will reopen it. (Read more at #912) Thanks! |
I'm kinda facing a similar issue. I have trouble getting accessToken from the session. Using MongoDB and EmailProvider method for Sign In. Since this issue is a bit old. I assume things are changed. This is how my import NextAuth from "next-auth";
import { MongoDBAdapter } from "@next-auth/mongodb-adapter";
import EmailProvider from "next-auth/providers/email";
import MongoClientPromise from "../../../lib/mongodb";
const THIRTY_DAYS = 30 * 24 * 60 * 60;
const THIRTY_MINUTES = 30 * 60;
export default NextAuth({
secret: process.env.SECRET,
session: {
strategy: "jwt",
maxAge: THIRTY_DAYS,
updateAge: THIRTY_MINUTES,
},
adapter: MongoDBAdapter(MongoClientPromise),
providers: [
EmailProvider({
server: {
host: process.env.EMAIL_SERVER_HOST,
port: process.env.EMAIL_SERVER_PORT,
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
},
},
from: process.env.EMAIL_FROM,
}),
],
}); When I tried to extract the accessToken from the session in the pages/index.js it's showing undefined. |
Could someone help me understand how I can retrieve the jwt token on client side? (with and without hooks) |
Why is this not documented? It's essential and basic functionality. JWT is not present in the session and the token property in the JWT call back is the decrypted token which contains a subset of the user object... why? Do we nee to to manually read the cookies and handle token retrieval for api requests not performed by next auth? |
@SemajDraw I had the same question but I found this from @iaincollins:
cf. #643 (comment) |
Your question
I have a Server side rendered page where I need to grab the JWT session token from my user, but i'm a little unsure how to go about getting it.
What are you trying to do
I want to get the JWT session token from my user on a server side rendered page... my code looks like this on the page:
However, this outputs:
I'm using a custom oAuth provider so my [...nextauth].js looks like this:
I suspect it's to do with my callbacks but none of my console.logs are triggering on the generate page.
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
The text was updated successfully, but these errors were encountered: