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
Using getSession from SSR (to implement authorized API calls for our needs) - as in https://next-auth.js.org/tutorials/securing-pages-and-api-routes -, once the access and refresh tokens are updated - as in https://next-auth.js.org/tutorials/refresh-token-rotation -, the next SSR with getSession will still see the old access and refresh tokens.
FWIW I tried to investigate nextauth source, and saw that the Set-Cookie from next/utils.js updating the session cookie storing the new token is performed as it should, but does not seem to reach the browser (when I look that up in web developer tools / network).
The above URL contains a simple minimal commit from next-auth-example that demonstrates the problem and a README file indicating precisely the steps to perform to try it.
Thanks for any help! I spent a lot of time on it and lost at what to do next to fix the problem :(
How to reproduce
(these instructions also in README of the above reproduction URL project)
Install:
a) npm install
b) create a .env.local with:
NEXTAUTH_URL=http://localhost:3001
NEXTAUTH_SECRET=3ec635dd8c7bce6790eeabe8d348abee5e9f82cc6650711eacc2cbd4935cfbee
c) npm run dev -- -p 3001
d) open http://localhost:3001 in your browser and check you see a home screen with a top-right signin button
Reproduce the problem:
sign in (filling username/password fields unnecessary)
click on the SSR link after 10 seconds from login (so that access
token expired), logs show:
current access token expired on 1646822124490, pretend successful API refresh using refresh token dummy_refresh_token
new access token expiration 1646822185388
awaited getSession, access token is now: refreshed_access_token
click back and click on the SSR link again (no waiting necessary), logs show:
current access token expired on 1646822124490, pretend successful API refresh using refresh token dummy_refresh_token
new access token expiration 1646822197936
awaited getSession, access token is now: refreshed_access_token
=> demonstrating the fact the old access and refresh tokens are used, not the refreshed ones on step 2
Expected behavior
the new access and refresh token (returned by the jwt callback) should be used in subsequent calls to getSession (and next jwt callback)
The text was updated successfully, but these errors were encountered:
gcottenc
added
the
triage
Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
label
Mar 9, 2022
#4075 (comment) is the correct/preferred solution here. For context, the getSession method does not update the cookie inside getServerSideProps as it doesn't care about the ctx.res object.
Environment
System:
OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i7-7700T CPU @ 2.90GHz
Memory: 2.67 GB / 31.31 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 14.15.3 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.3.0 - /usr/local/bin/npm
Browsers:
Chrome: 96.0.4664.93
Firefox: 97.0.2
Reproduction URL
https://github.com/gcottenc/next-auth-example
Describe the issue
Using getSession from SSR (to implement authorized API calls for our needs) - as in https://next-auth.js.org/tutorials/securing-pages-and-api-routes -, once the access and refresh tokens are updated - as in https://next-auth.js.org/tutorials/refresh-token-rotation -, the next SSR with getSession will still see the old access and refresh tokens.
FWIW I tried to investigate nextauth source, and saw that the Set-Cookie from next/utils.js updating the session cookie storing the new token is performed as it should, but does not seem to reach the browser (when I look that up in web developer tools / network).
The above URL contains a simple minimal commit from next-auth-example that demonstrates the problem and a README file indicating precisely the steps to perform to try it.
Thanks for any help! I spent a lot of time on it and lost at what to do next to fix the problem :(
How to reproduce
(these instructions also in README of the above reproduction URL project)
Install:
a) npm install
b) create a .env.local with:
NEXTAUTH_URL=http://localhost:3001
NEXTAUTH_SECRET=3ec635dd8c7bce6790eeabe8d348abee5e9f82cc6650711eacc2cbd4935cfbee
c) npm run dev -- -p 3001
d) open http://localhost:3001 in your browser and check you see a home screen with a top-right signin button
Reproduce the problem:
sign in (filling username/password fields unnecessary)
click on the SSR link after 10 seconds from login (so that access
token expired), logs show:
current access token expired on 1646822124490, pretend successful API refresh using refresh token dummy_refresh_token
new access token expiration 1646822185388
awaited getSession, access token is now: refreshed_access_token
current access token expired on 1646822124490, pretend successful API refresh using refresh token dummy_refresh_token
new access token expiration 1646822197936
awaited getSession, access token is now: refreshed_access_token
=> demonstrating the fact the old access and refresh tokens are used, not the refreshed ones on step 2
Expected behavior
the new access and refresh token (returned by the jwt callback) should be used in subsequent calls to getSession (and next jwt callback)
The text was updated successfully, but these errors were encountered: