admin 管理员组文章数量: 1086019
callbacks: {
async jwt({ token, user }) {
if (user) {
token.user = jwtDecode<UserToken>(user.accessToken);
token.user.accessToken = user.accessToken;
if (token.user.exp) {
token.exp = token.user.exp;
}
}
console.log('JWT Callback - Token Exp:', token.exp); // Debugging
return token;
},
async session({ session, token }) {
Object.assign(session.user, token.user ?? {});
if (token.exp) {
session.expires = new Date(token.exp * 1000).toISOString();
}
console.log('Session Callback - Session Expires:', session.expires); // Debugging
return session;
},
}
What I’ve tried: Logging token.exp in both jwt and session callbacks (it seems correctly assigned).
Ensuring token.user.exp exists before assigning it to token.exp.
Clearing cookies and trying a fresh login.
Expected Behavior: session.expires should be updated correctly using the exp value from the token.
Actual Behavior: session.expires does not reflect the expected expiration time, and remains unchanged or incorrect.
Manually setting maxAge in session: { maxAge: 60 * 60 }, which works, but I want it to be dynamic based on the token’s exp.
Expected Behavior: session.expires should be updated correctly using the exp value from the token.
Actual Behavior: session.expires does not reflect the expected expiration time, and remains unchanged or incorrect.
How can I ensure that session.expires correctly updates from token.exp dynamically?
本文标签: authenticationNextAuthjs sessionexpires not updating correctly from JWT expStack Overflow
版权声明:本文标题:authentication - NextAuth.js session.expires not updating correctly from JWT exp - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743987320a2514091.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论