-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unstable_getServerSession Not Updating Session After Redirect #5223
Comments
It seems adding the following event forces the session to refresh. const event = new Event('visibilitychange');
document.dispatchEvent(event); If I add this right before redirecting, it seems to work as a temporary workaround. Is there a more official way to make this work? All of the existing discussions I have found have lead me nowhere unfortunately. |
I have the same question |
Thanks for the detailed bug report @joepetrillo |
It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks! |
To keep things tidy, we are closing this issue for now. If you think your issue is still relevant, leave a comment and we might reopen it. Thanks! |
it does still exist, im using credentials + google provider, i have followed with database strategy, setup cookie from signin callback, and jwt for session but once i disabled http cookie, noticed after redirect the cookie was removed. |
This is still an issue. I have a redirect that's done by Stripe after the webhook is finished processing and it doesn't load the correct page. The object is also not the correct one, although the session callback returns the correct object. |
Environment
System:
OS: macOS 12.5
CPU: (10) arm64 Apple M1 Max
Memory: 2.42 GB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.16.0 - ~/Library/Caches/fnm_multishells/15888_1661372974805/bin/node
npm: 8.11.0 - ~/Library/Caches/fnm_multishells/15888_1661372974805/bin/npm
Browsers:
Chrome: 104.0.5112.101
Firefox Developer Edition: 104.0
Safari: 15.6
npmPackages:
next: 12.2.5 => 12.2.5
next-auth: ^4.10.3 => 4.10.3
react: 18.2.0 => 18.2.0
Reproduction URL
https://github.com/joepetrillo/lone-link
Describe the issue
I am using the email login provider. I need usernames for my application, so I redirect users who do not have one to a setup profile page. This page simply does some validation of input and updates the name field in my db for the currently logged in user. (null by default) A user will always be redirected here until their name is not null or empty.
Once this completes, I redirect from this setup page to the dashboard page using next router.
router.push("/dashboard");
Both the setup page and the dashboard page are getting the session on the server using
unstable_getServerSession
.I then pass the session as a page prop and use
useSession()
to get the session. In the getgetServerSideProps
function I logged the session retrieved before passing it as a page prop.See this video
https://user-images.githubusercontent.com/32227357/186795104-5a7b6eaf-c095-47a3-96eb-5fc1fb0b8905.mov
As expected the first session on the setup page has a null name

When I redirect, the dashboard session gets the proper name and session.

However, on the page it does not appear correctly until I refresh.

I have been trying to figure this out for a while now, any help is greatly appreciated but I am thinking it could be a bug so wanted to report here.
Thanks!
How to reproduce
Redirect from one page to another that both retrieve the session on the server side.
Expected behavior
The dashboard page should not have to refresh to get access to the session.
The text was updated successfully, but these errors were encountered: