Next Auth JWT Refresh across multiple tabs #8408
Unanswered
ArcaneTSGK
asked this question in
Help
Replies: 2 comments
-
We have exactly the same problem. I've tried to follow discussion on #3940. It looks like this has been an issue 2 years ago and still an issue. I might be wrong. We just started using next-auth and ran into this problem. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I also had similar problem in multiple tabs. I am switching to Lucia auth |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question 💬
Hi, I am attempting to implement the refresh flow as shown in the docs. I have successfully implemented this when the user is on a single tab, but when using multiple tabs in the same browser, or when spamming the refresh button, the auth flow breaks and signs the user out.
EDIT: It appears I was wrong, it is not multiple tabs causing the problem but the second refresh.
Please can someone take a look and make any suggestions to help solve this issue? Thanks
EDIT 2: Looks like it is related to this and there is not yet a suitable workaround #6642
How to reproduce ☕️
next-auth: 4.23.1
next: 13.4.9
react: 18.2.0
node: 18.17.0
pnpm: 8
route.ts:
options.ts
As stated, this works perfectly fine in a single tab, I've set the accesstoken to expire at 60 seconds, so predictably at >50 seconds when refreshing the page or navigating protected routes it refreshes the token and I get new accessToken and refreshToken. If I have two tabs open at the same time as requiring a refresh then the tab that has a browser refresh second seems to have stale JWT token data, which then causes a 404 on the /refresh api and signs the user out.
Any help would be appreciated.
Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
Beta Was this translation helpful? Give feedback.
All reactions