javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Infinite redirect loop in NextJS development environment

Open ghost opened this issue 3 years ago • 101 comments

Description

I'm getting this error constantly after logging into an account. This is development environment and running on localhost

screenshot

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",
  }
}

ghost avatar Jun 29 '23 16:06 ghost

On my windows PC, syncing with the time server solved the issue. It might occur again, but I am good for now

Does anybody encouter it on production app? where use 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)

Yikes, you're definitely right about that, there has to be like a workaround around this.

creative-tutorials avatar Aug 19 '23 07:08 creative-tutorials

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?

emLuc86dev avatar Aug 19 '23 23:08 emLuc86dev

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 is 0 instead of some timestamp like 1692272951

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.

kachar avatar Aug 20 '23 06:08 kachar

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 is 0 instead of some timestamp like 1692272951

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 didn't get this bad value, All I needed was to change the time zone. Thanks for sharing by the way

creative-tutorials avatar Aug 20 '23 17:08 creative-tutorials

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?

Which OS are you using If I may ask @emLuc86dev

creative-tutorials avatar Aug 20 '23 17:08 creative-tutorials

I"m using Windows 11. I changed my time and time zone. I cleared the cache and cookies and I'm still getting the same error. Then I tried another web browser and still the same... Thanks for your time

El dom, 20 de ago de 2023 1:49 p. m., Timi @.***> escribió:

I am using @.***/nextjs": "^4.23.2". I have changed the time and time zone and I still getting the same error ... Does anyone have a solutions?

Which OS are you using If I may ask?

— Reply to this email directly, view it on GitHub https://github.com/clerkinc/javascript/issues/1436#issuecomment-1685352120, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUXR5LLQAMTKQI4F4D5HM43XWJE2DANCNFSM6AAAAAAZYYYU6Q . You are receiving this because you commented.Message ID: @.***>

emLuc86dev avatar Aug 20 '23 23:08 emLuc86dev

[image: image.png]

El dom, 20 ago 2023 a la(s) 19:07, Emilio Salvia @.***) escribió:

I"m using Windows 11. I changed my time and time zone. I cleared the cache and cookies and I'm still getting the same error. Then I tried another web browser and still the same... Thanks for your time

El dom, 20 de ago de 2023 1:49 p. m., Timi @.***> escribió:

I am using @.***/nextjs": "^4.23.2". I have changed the time and time zone and I still getting the same error ... Does anyone have a solutions?

Which OS are you using If I may ask?

— Reply to this email directly, view it on GitHub https://github.com/clerkinc/javascript/issues/1436#issuecomment-1685352120, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUXR5LLQAMTKQI4F4D5HM43XWJE2DANCNFSM6AAAAAAZYYYU6Q . You are receiving this because you commented.Message ID: @.***>

emLuc86dev avatar Aug 21 '23 00:08 emLuc86dev

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.

image

thanks when i setup then restart computer that okay;

jokereven avatar Aug 21 '23 13:08 jokereven

Hi mate I'm having this bug yet... I've tried everything, cleared cookies and cache, changed time and time zone automatically. I deleted the project and created it from scratch and still have the same infinity loop bug....

El lun, 21 ago 2023 a la(s) 09:21, zhou jing @.***) escribió:

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.

[image: image] https://user-images.githubusercontent.com/68476321/260267986-2a4edf9f-dee4-436b-9a1b-a48cb9913469.png

thanks when i setup then restart computer that okay;

— Reply to this email directly, view it on GitHub https://github.com/clerkinc/javascript/issues/1436#issuecomment-1686319785, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUXR5LM5OT3J6BQGIENK4QTXWNOFDANCNFSM6AAAAAAZYYYU6Q . You are receiving this because you were mentioned.Message ID: @.***>

emLuc86dev avatar Aug 21 '23 21:08 emLuc86dev

@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

fanckush avatar Aug 22 '23 07:08 fanckush

I"m using Windows 11. I changed my time and time zone. I cleared the cache and cookies and I'm still getting the same error. Then I tried another web browser and still the same... Thanks for your time El dom, 20 de ago de 2023 1:49 p. m., Timi @.> escribió: … I am using @./nextjs": "^4.23.2". I have changed the time and time zone and I still getting the same error ... Does anyone have a solutions? Which OS are you using If I may ask? — Reply to this email directly, view it on GitHub <#1436 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUXR5LLQAMTKQI4F4D5HM43XWJE2DANCNFSM6AAAAAAZYYYU6Q . You are receiving this because you commented.Message ID: @.***>

I want you to sign out of your app first, so sign out, clear cookies, local storage, session storage, and browsing data for your app. Then change the time and zone, as I screenshot earlier, then try again. One thing I've noticed is to try different devices. You can either host it online to test it or use ngrok. If still that didn't work send you can DM me the project let me take a look

creative-tutorials avatar Aug 22 '23 10:08 creative-tutorials

@emLuc86dev maybe this #1566 is the cause of your bug? it also causes infinite loop but for a different reason that the timezone one

Now this one I've not seen before, @emLuc86dev try using the debug mode and share what error you seem to be having

creative-tutorials avatar Aug 22 '23 10:08 creative-tutorials

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. image

thanks when i setup then restart computer that okay;

You're welcome @jokereven

creative-tutorials avatar Aug 22 '23 10:08 creative-tutorials

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 is 0 instead of some timestamp like 1692272951

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.

Is your staging using Dev keys from Clerk? If so, we would recommend either:

  • using production keys (sharing the user base) for staging so the cookies are the same
  • using a second domain and a second, free Production instance for staging to have a limited user base.

royanger avatar Aug 22 '23 14:08 royanger

I"m using Windows 11. I changed my time and time zone. I cleared the cache and cookies and I'm still getting the same error. Then I tried another web browser and still the same...

Did you add debug: true (see https://github.com/clerkinc/javascript/issues/1436#issuecomment-1668728895)? If so, what were the results of the log?

royanger avatar Aug 22 '23 14:08 royanger

This error happens after a long time of not using the app. The session token will expire at that time, and a page on the site needs to load to refresh. This is what I've noticed; not sure if it's what's happening.

For me, if I don't use the app for a long time, and then I visit a protected page hoping that I'll be redirected, typically, the error shows up, but at that time, Clerk would have done refresh, and when I reload the page, everything works fine again. I am sure that it's not an issue with my time.

Has anyone else noticed the same thing?

ghost avatar Aug 23 '23 09:08 ghost

I'm now pretty sure that this is what is happening, at least for me.

The token is usually expired when loading the app after a long time.

ghost avatar Aug 23 '23 10:08 ghost

Maybe someone else should try it

ghost avatar Aug 23 '23 10:08 ghost

This issue has been open for nearly 2 months and now encapsulates several different issues from different people, some resolved, some maybe not. In an effort to clean things up a bit, going to close this out. Please do not interpret this as us not caring - we know that this error has been difficult for many, and have been discussing how to improve it internally. Please feel free to open a new issue, ideally with a reproduction, for anyone still encountering this issue!

jescalan avatar Aug 25 '23 16:08 jescalan

I am still encountering this issue. syncing the timezone didn't solve the problem

salehelsayed avatar Oct 15 '23 17:10 salehelsayed