Infinite redirect loop in NextJS development environment
Description
I'm getting this error constantly after logging into an account. This is development environment and running on localhost
Package + Version
- [ ]
@clerk/clerk-js - [ ]
@clerk/clerk-react - [x]
@clerk/nextjs - [ ]
@clerk/remix - [ ]
@clerk/types - [ ]
@clerk/themes - [ ]
@clerk/localizations - [ ]
@clerk/clerk-expo - [ ]
@clerk/backend - [ ]
@clerk/clerk-sdk-node - [ ]
@clerk/shared - [ ]
@clerk/fastify - [ ]
@clerk/chrome-extension - [ ]
gatsby-plugin-clerk - [ ]
build/tooling/chore - [ ] other:
{
"dependencies": {
"@clerk/nextjs": "^4.21.12",
"next": "13.4.7",
}
}
Hello @Aayushpatil77 and thank you for opening this issue.
If the issue is not resolved after trying the 3 Reasons described in the error message, could you provide a repository that reproduces this error to investigate it more and get back to you?
Same issue here.
Using Next.js and getting an infinite redirect. But when we refresh the page again, it will work as expected.
GitHub repo example->https://github.com/adarsh-gupta101/Next-full-stack-editor
@dimkl Github repo :- https://github.com/Aayushpatil77/ecommerce-dashboard
Had sort of the same issue. It works fine on localhost, but when I try to proxy (e.g. using ngrok) the browser gets stuck in an infinite loop. In my case, React does not display any error message.
I tried to run the debugger in Chrome; found this line to be the "culprit": https://github.com/clerkinc/javascript/blob/019992f2063ba8580446edf98c760eabcc8fc71a/packages/backend/src/tokens/interstitial.ts#L101-L102
Why would my page suddenly have an empty fragment? I would expect that it is added in the call itself e.g.
- window.location.href = window.location.href;
+ window.location.href = window.location.href + "#";
This was with version @clerk/nextjs==4.19.0, seems fixed in @clerk/nextjs==4.21.13
I got this error after switching auth providers to Clerk, I got it to work by clearing my old cookies.
I got the same problem. Fresh install of T3, installed clerk, followed quick start docs, first npm run dev and i got this error. Tried everything. Skewing time updating, checked keys. It doesn't work
This was with version
@clerk/nextjs==4.19.0, seems fixed in@clerk/nextjs==4.21.13
I am using "@clerk/nextjs": "^4.23.2" this version and still getting the error... If anyone knows how to fix it please do let me know
On my windows PC, syncing with the time server solved the issue. It might occur again, but I am good for now
Yeah it also worked for me
I am facing the same issue as of now. It was working fine the day before i was developing the app. when i ran the Next app again the next day, it's showing the infinite loop error. Is their any particular reason??
Clerk needs your system clock to be in sync with your current timezone. I synced my system timezone correctly. The clerk is working fine.
Clerk needs your system clock to be in sync with your current timezone. I synced my system timezone correctly. The clerk is working fine.
Yeah that was the problem
Tried syncing my time, still the same issue
If you are experiencing this in NextJS, please add debug: true to your authMiddleware. See https://clerk.com/docs/nextjs/middleware#middleware-argument-types. This will give you debugging loads which can produce more information.
If you see an error like the one below, then it is indicating your clock is out of sync.
[0] "message": "JWT issued at date claim (iat) is in the future. Issued at date: Mon Jul 10 2023 19:40:49 GMT+0200 (Central European Summer Time); Current date: Mon Jul 10 2023 19:40:38 GMT+0200 (Central European Summer Time); (reason=token-not-active-yet, token-carrier=cookie)"
When I try clearing the cookies it works for me, but after saving a few changes to my code, it doesn't work anymore
GitHub Repo --> https://github.com/creative-tutorials/resubase
If you are experiencing this in NextJS, please add
debug: trueto your authMiddleware. See https://clerk.com/docs/nextjs/middleware#middleware-argument-types. This will give you debugging loads which can produce more information.If you see an error like the one below, then it is indicating your clock is out of sync.
[0] "message": "JWT issued at date claim (iat) is in the future. Issued at date: Mon Jul 10 2023 19:40:49 GMT+0200 (Central European Summer Time); Current date: Mon Jul 10 2023 19:40:38 GMT+0200 (Central European Summer Time); (reason=token-not-active-yet, token-carrier=cookie)"
Thanks for the tip, it shows much clearer information now, the state for isSignedIn seems to be treated as false, with a JWT message
Issued at date: Mon Jul 10 2023 19:40:49 GMT+0200 (Central European Summer Time); Current date: Mon Jul 10 2023 19:40:38 GMT+0200 (Central European Summer Time); (reason=token-not-active-yet, token-carrier=cookie)
This is confirming that your clock is out of sync and in the future. Syncing your clock with a time server should resolve this error.
Issued at date: Mon Jul 10 2023 19:40:49 GMT+0200 (Central European Summer Time); Current date: Mon Jul 10 2023 19:40:38 GMT+0200 (Central European Summer Time); (reason=token-not-active-yet, token-carrier=cookie)
This is confirming that your clock is out of sync and in the future. Syncing your clock with a time server should resolve this error.
Thank you very much, it turns out that toggling "Set time automatically" and "Set time zone automatically", with synchronizing the time, and properly setting my time zone did the trick.
On my windows PC, syncing with the time server solved the issue. It might occur again, but I am good for now
Does anybody encounter it on production app? where end users doesn't sync with time server from windows settings? I mean, We developer fixing it on our device but what if it happens same with end users ? Where they didn't sync with time server?
(Mine also fixed with time server sync)