Open Natchii59 opened 1 year ago
the same as you
hard to tell if this is the I'm seeing but I'm seeing something similar whenever the user comes back to the tab and a session is retrieved via a visibilitychange
event. What's happening is that a broadcast occurs as a result of retrieving the session which the active tab that already retrieved the session also receives that broadcast message and triggers another session retrieval. Potentially, other code paths like update
can be causing the same behavior which it triggers a broadcast and the active tab unnecessarily handles that broadcast message
stepping through the code for the visibiltychange
example
visibilitychange
calls _getSession
_getSession
calls getSession
with broadcast
set to `truegetSession
triggers broadcast
_getSession
calldue to the broadcast handler calls _getSession
with storage
event, it prevents any more session retrievals from happening
this is impacting v5.0.0-beta.5
the solution here would be to edit this line:
and make it:
__NEXTAUTH._session = await getSession({ broadcast: false })
since getSession by default calls storage
to broadcast, the visibiltychange
gets called calls getSession({ broadcast:false }), it doesn't loop back into a storage broadcast, but instead just updates the user and ends at that, so everything else that explicitly calls storage
will only do it once, and every other event name will have broadcast off and call once.
Environment
System:
Binaries:
Browsers:
Reproduction URL
https://github.com/Natchii59/next-chat
Describe the issue
I would like to update my JWT data, and for that I need to put the
SessionProvider
at the root of the page. To then use theuseSession
which gives access to theupdate
function. The problem is that it creates 2 calls to the jwt and session callbacks each time the page is refreshed. How to fix this?How to reproduce
Add a
SessionProvider
to the project and put aconsole.log
in a NextAuth options callback.Expected behavior
I wish I didn't have callbacks double call with a
SessionProvider
. Or another way to update my JWT data without usingSessionProvider
.