next-auth: Session not being persisted when I close the browser
Hi, Is there a way to persist the session? As soon as I close the browser, the user is being logged out.
When I saw the cookies that are set, I see Expires/Max-Age
value of next-auth.session-token
set to Session
. I am using the default configuration. By default, I assumed the max-age will be set to 30 days as per documentation. But that doesn’t seem to be the case. Am I missing something?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (7 by maintainers)
@balazsorban44 I was able to fix it. Thanks for pointing out the relevant code.
Here is the diff: https://github.com/pbteja1998/nextjs-starter/commit/9d885ae5d88e443fe6d1a3e69ddcd6e99e6c9470
As far as I know. (haven’t tested other adapters). @pbteja1998 then we would be glad to accept a PR from you to fix this! 🙂
@balazsorban44 yeah I’d say update that file in the fauna adapter. This only affects that adapter, right?
Good work @pbteja1998!
In the adapter, the one you just linked. I would check the
updateSession
function to begin with.Also, here is the code being called when calling the
/api/auth/session
endpoint:https://github.com/nextauthjs/next-auth/blob/78fd783bac990d8f2109487ac6598a38e3173f40/src/server/routes/session.js#L61-L94
As you can see, this should update the cookie expiry whenever session is accessed. In case the sessionToken was found but invalid, the cookie will be removed. So I would also check the
getSession
function.(Hint: add
debug: true
to your NextAuth options to log more information while debugging)