Skip to content
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

Closed
joepetrillo opened this issue Aug 26, 2022 · 7 comments
Closed

unstable_getServerSession Not Updating Session After Redirect #5223

joepetrillo opened this issue Aug 26, 2022 · 7 comments
Labels
duplicate This issue or pull request already exists stale Did not receive any activity for 60 days

Comments

@joepetrillo
Copy link

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

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 get getServerSideProps 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
image

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

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

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.

@joepetrillo joepetrillo added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Aug 26, 2022
@joepetrillo
Copy link
Author

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.

@fivaz
Copy link

fivaz commented Aug 31, 2022

I have the same question

@ThangHuuVu
Copy link
Member

ThangHuuVu commented Sep 2, 2022

Thanks for the detailed bug report @joepetrillo
This does not seem like a unstable_getServerSession issue though, but more like a duplicate of #2129 🤔

@ThangHuuVu ThangHuuVu added duplicate This issue or pull request already exists and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Sep 4, 2022
@stale
Copy link

stale bot commented Nov 9, 2022

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!

@stale stale bot added the stale Did not receive any activity for 60 days label Nov 9, 2022
@stale
Copy link

stale bot commented Nov 22, 2022

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!

@stale stale bot closed this as completed Nov 22, 2022
@dellwatson
Copy link

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.

@AveshLutchman
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists stale Did not receive any activity for 60 days
Projects
None yet
Development

No branches or pull requests

5 participants