https://remaster.com/blog/next-auth-jwt-session
jwt
CallbackWhat It Does:
token
and user
as parameters.Parameters:
token
: Existing or new token object.user
: User object from authorize
.Usage:
token
.token
.Example Code:
jwt: async (token, user) => {
if (user) {
token.id = user.id;
token.email = user.email;
}
return token;
}
Note:
token
is automatically encrypted by NextAuth.js.session
CallbackWhat It Does:
session
and token
as parameters.Parameters:
session
: Existing session object.token
: Encrypted token from jwt
callback.Usage:
session
.session
.Example Code:
session: async (session, token) => {
session.user.id = token.id;
return session;
}
Note:
session
is sent to the client.