You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
callbacks: {
async session(session, token) {
// Add property to session, like an access_token from a provider
if (token?.user) {
const { user } = token;
session.accessToken = user.accessToken;
// where accessTokenExpirary = new Date(user.decodedToken.exp * 1000)
session.expires = accessTokenExpirary;
}
return session;
},
async jwt(token, user, account, profile, isNewUser) {
if (account?.type === "credentials" && user) {
token.user = user;
}
return token;
},
},
Expected behavior
By overwriting the session objects expires value, i would have expected to overwrite the default expired value. This is not happening. I'm not able to overwrite the expirary time
Additional context
I want to be able to control the expirary of the session based on the expirary of the accessToken returned from the server. So if the accessToken expires in 10 days, I also want the session to expire in 10 days.
Setting the maxAge works fine. It's just I'm not able to dynamically set the expirary. In my case I want the session to expire as soon as the jwt accessToken returned by the server expires.
This discussion was converted from issue #1457 on March 06, 2021 11:13.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I'm not able to overwrite the session expirary using the session callback when using when using custom Credentials provider
Steps to reproduce
[...nextauth].js
set default expirary in thesession
option e.g.session
callback overwrite the session objectExpected behavior
By overwriting the session objects
expires
value, i would have expected to overwrite the default expired value. This is not happening. I'm not able to overwrite the expirary timeAdditional context
I want to be able to control the expirary of the session based on the expirary of the accessToken returned from the server. So if the accessToken expires in 10 days, I also want the session to expire in 10 days.
Setting the maxAge works fine. It's just I'm not able to dynamically set the expirary. In my case I want the session to expire as soon as the jwt accessToken returned by the server expires.
Beta Was this translation helpful? Give feedback.
All reactions