javascript: 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
-
@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",
}
}
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 91 (8 by maintainers)
Commits related to this issue
- feat(nextjs): Drop support for next@12, next<13.0.4, next<14.0.3 Drop support for NextJS v12: v12 was released on 26 Oct 2021 (~2 years ago). Security support ended on 21 Nov 2022 (~11 months ago) ... — committed to clerk/javascript by nikosdouvlis 7 months ago
- feat(nextjs): Drop support for next@12, next<13.0.4, next<14.0.3 Drop support for NextJS v12: v12 was released on 26 Oct 2021 (~2 years ago). Security support ended on 21 Nov 2022 (~11 months ago) ... — committed to clerk/javascript by nikosdouvlis 7 months ago
- feat(nextjs): Drop support for next@12, next<13.0.4, next<14.0.3 Drop support for NextJS v12: v12 was released on 26 Oct 2021 (~2 years ago). Security support ended on 21 Nov 2022 (~11 months ago) ... — committed to clerk/javascript by nikosdouvlis 7 months ago
- feat(nextjs): Drop support for next@12, next<13.0.4, next<14.0.3 Drop support for NextJS v12: v12 was released on 26 Oct 2021 (~2 years ago). Security support ended on 21 Nov 2022 (~11 months ago) ... — committed to clerk/javascript by nikosdouvlis 7 months ago
- feat(nextjs): Improve top-level API surface and drop unsupported versions (#2347) * feat(nextjs): Drop support for next@12, next<13.0.4, next<14.0.3 Drop support for NextJS v12: v12 was released o... — committed to clerk/javascript by nikosdouvlis 7 months ago
We’ve noticed. that certain users have bad cookie values which causes the infinite loop.
The cookie name is
__client_uat
and the bad value is0
instead of some timestamp like1692272951
Once we clear this cookie the redirect loops are gone.
Our observation of this cookie is that it gets a bad value when we switch between the subdomains of our app - Production / Staging.
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
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.
This was with version
@clerk/nextjs==4.19.0
, seems fixed in@clerk/nextjs==4.21.13
We are experiencing the exact same error since releasing our production environment. The issue might be tied to the
__client_uat
cookie which is available twice if both the develop and the main instance are running on the same domain.We have the following scenario:
a.b.c.mysite.io
app.mysite.io
This is the cookie we see on main:
__client_uat = <timestamp>
This is what we see on develop:
__client_uat = <timestamp>
__client_uat = 0
Once one has visited the main site with their browser and switches to develop to test something, the site is trapped in an infinite loop with the error referring to the said cookie, ie.
The Cookie '__client_uat' has been rejected for invalid domain.
We have to painfull clear the cookies, refresh everything and refrain from accessing the live site in the same session. It never occurs on
localhost
. Anybody else having this issue?(Node v18.17.0, @clerk/nextjs v4.29.3, in Docker)
I was getting this error when using
node
v20, switching back to 18 resolved it for meI got this error after switching auth providers to Clerk, I got it to work by clearing my old cookies.
@stx-chris @creative-tutorials @jameslporter After digging heavily into Next’s internals, as well as performing a number of tests with SSL termination and reverse proxying, I’m fairly confident that the PR we submitted to Next.js earlier today, will solve these issues.
Currently, the PR is approved and, once merged, the changes will be available as a canary build of
v14.0.3
.In the meantime, you should should be able to mitigate these issues by setting the
X-Forwarded-Host
request header to theHost
header via Varnish, or otherwise.This was my configuration via Caddy:
In short, if
X-Forwarded-Host
is already set, Next doesn’t overwrite it with the incorrect value.I am using “@clerk/nextjs”: “^4.23.2”. I have changed the time and time zone and I still getting the same error … Does anyone have a solutions?
On my windows PC, syncing with the time server solved the issue. It might occur again, but I am good for now
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
I just ran into the same issue after updating my node to v.21. I resolved the issue by downgrading node to v.18 and updating nextjs to v.14.1.0. Hope this might help someone!
cleared cookies, changed node version (v18.18.2), and she works :–) thanks all
After changing node 20.10.0 to node 18.12.1, it working fine.
I had same issue but I solved it.
The following is what we did this time.
thanks when i setup then restart computer that okay;
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.
Tried syncing my time, still the same issue
Yes, upgrading my Next.js (‘^14.2.1’) worked for me. Just do
npm install next@latest
and it should install the latest Next.js which should resolve this issue with clerk.It only helped for the initial page load but same issue after I refreshed. I have figured out the final fix now. Seem to be a Nextjs Issue. Upgrading to 14.1.3 solved the issue eventually. https://github.com/vercel/next.js/issues/55648
We are also having this issue. Still have no clue how to fix it.
Try syncing your clock please
I still have this issue. I have cleared cache and cookies, I have gone from node v21 to v18, I have changed date and time on and off. I am using localhost:3000
Thanks, It worked for me. i was on node v21, switched back to 18 and it’s working
If only the people who knew the answer were here to help. Godspeed and good luck! Maybe if you share more about your docker setup we can find out what isn’t quite right.
On Wed, Nov 15, 2023, 9:47 AM stx-chris @.***> wrote:
Nope I’m on 14 as well. It’s not a code problem. It’s how you are running it. Again the only way I’ve gotten it to work properly for http localdev is to use localhost:3000. Getting kind of frustrated with the lack of support here. I feel like I’m the clerk support staff trying to help others through the problems I experienced. I really just want confirmation that my hypothesis is correct and if so this be stated clearly in the documentation. My requests have fallen on deaf ears.
On Wed, Nov 15, 2023 at 9:30 AM stx-chris @.***> wrote:
Did you add
debug: true
(see https://github.com/clerkinc/javascript/issues/1436#issuecomment-1668728895)? If so, what were the results of the log?Is your staging using Dev keys from Clerk? If so, we would recommend either:
@emLuc86dev maybe this https://github.com/clerkinc/javascript/issues/1566 is the cause of your bug? it also causes infinite loop but for a different reason that the timezone one
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)
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)"