adrianhajdin / threads

Develop Threads, Next.js 13 app that skyrocketed to 100 million sign-ups in less than 5 days, and dethroned giants like Twitter, ChatGPT, and TikTok to become the fastest-growing app ever!
https://threads-psi.vercel.app
1.52k stars 291 forks source link

Clerk: Clock skew detected #86

Open PrtHub opened 1 year ago

PrtHub commented 1 year ago

Error: Clerk: Clock skew detected. This usually means that your system clock is inaccurate. Clerk will continuously try to issue new tokens, as the existing ones will be treated as "expired" due to clock skew.

To resolve this issue, make sure your system's clock is set to the correct time (e.g. turn off and on automatic time synchronization).


JWT cannot be used prior to not before date claim (nbf). Not before date: Thu, 28 Sep 2023 06:35:34 GMT; Current date: Thu, 28 Sep 2023 06:35:04 GMT; (reason=token-not-active-yet, token-carrier=cookie)

MatthewAraujo commented 1 year ago

I get this error all the time, I usually speed up the timer and stop this error but I think it is something clerk is trying to fix

maxidv88 commented 1 year ago

I have the same problem when I try to login with Clerk authentication.

maxidv88 commented 1 year ago

In my case I'm running WSL2 with Ubuntu in my Windows 11 machine. When I checked the time in the ubuntu terminal (where the nextjs app is running) it was out of sync with Windows so I had to update it manually with the following command sudo hwclock -s. After that the problem was solved. I read that it's a common problem when the computer go to sleep, the Ubuntu clock gets out of sync with Windows.

rukemn commented 1 year ago

Encountered the same Problem on WSL2, computer was also put to sleep before . sudo hwclock -s did not fix it for me, only restarting the server a second time does it for me.

TomaszKulaDev commented 1 year ago

` 1 of 1 unhandled error Server Error Error: Clerk: Clock skew detected. This usually means that your system clock is inaccurate. Clerk will continuously try to issue new tokens, as the existing ones will be treated as "expired" due to clock skew.

To resolve this issue, make sure your system's clock is set to the correct time (e.g. turn off and on automatic time synchronization).


JWT cannot be used prior to not before date claim (nbf). Not before date: Sat, 07 Oct 2023 17:50:14 GMT; Current date: Sat, 07 Oct 2023 17:50:07 GMT; (reason=token-not-active-yet, token-carrier=cookie)

This error happened while generating the page. Any console logs will be displayed in the terminal window. Call Stack assertClockSkew node_modules\@clerk\nextjs\dist\esm\server\authMiddleware.js (173:10) assertClockSkew node_modules\@clerk\nextjs\dist\esm\server\authMiddleware.js (73:6) async adapter node_modules\next\dist\esm\server\web\adapter.js (150:19) async runWithTaggedErrors file:///C:/Users/xxx/Desktop/nextjs13/node_modules/next/dist/server/web/sandbox/sandbox.js (96:24) async DevServer.runMiddleware file:///C:/Users/xxx/Desktop/nextjs13/node_modules/next/dist/server/next-server.js (962:24) async DevServer.runMiddleware file:///C:/Users/xxx/Desktop/nextjs13/node_modules/next/dist/server/dev/next-dev-server.js (250:28) async DevServer.handleCatchallMiddlewareRequest file:///C:/Users/xxx/Desktop/nextjs13/node_modules/next/dist/server/next-server.js (1051:22) async DevServer.handleRequestImpl file:///C:/Users/xxx/Desktop/nextjs13/node_modules/next/dist/server/base-server.js (736:32)`

FredDaFed commented 1 year ago

If you are using WSL with windows, it will be slightly off.

ISSUE: image

SOLUTION: If you go into your Ubuntu WSL terminal, the command below will fix the issue:

sudo apt install ntpupdate && sudo ntpdate pool.ntp.org

RESULTS: 9 Oct 06:46:10 ntpdate[31661]: step time server 129.250.35.250 offset +148.127650 sec Restart your server then it should work as seen below: image After Signing in and accessing secured page: image

Checking home page after signing in: image

Diwanshumidha commented 1 year ago

I dont have wsl setup in my computer still getting this problem

Rhishikesh12 commented 1 year ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

image

This fixed my issue, You can give it a try.

ariandanim commented 1 year ago

I am using Windows 11 the latest 22H2, I am only set to ON in this setting date & time image

Roeck commented 1 year ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

* Click on **"Settings"** in the Windows Start menu.

* Navigate to **"Time & Language"** within the Settings menu.

* Select **"Date & Time"** from the Time & Language options.

* Click on **"Additional Settings."**

* Finally, select **"Sync now"** to synchronize your system's date and time settings.

image

This fixed my issue, You can give it a try.

I've just tried that, including restarting the system. This error just started happening suddenly, the app was opening normally and I didn't change any date and time settings. I also checked my project on Clerk and everything seems fine on there. What else could it be?

Roeck commented 1 year ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

* Click on **"Settings"** in the Windows Start menu.

* Navigate to **"Time & Language"** within the Settings menu.

* Select **"Date & Time"** from the Time & Language options.

* Click on **"Additional Settings."**

* Finally, select **"Sync now"** to synchronize your system's date and time settings.

image

This fixed my issue, You can give it a try.

I've tried that but unfortunately it's still happening. I didn't mess with my date and time settings, the project was opening normally and that issue just suddenly started happening! This is so odd. What else could that be?

Roeck commented 1 year ago

I've tried fixing the time on settings but unfortunately it's still happening. I didn't mess with my date and time settings, the project was opening normally and that issue just suddenly started happening! This is so odd. What else could that be?

annandltp commented 1 year ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

  • Click on "Settings" in the Windows Start menu.
  • Navigate to "Time & Language" within the Settings menu.
  • Select "Date & Time" from the Time & Language options.
  • Click on "Additional Settings."
  • Finally, select "Sync now" to synchronize your system's date and time settings.

image

This fixed my issue, You can give it a try.

this work, thanks

TomaszKulaDev commented 1 year ago

Well i fix it but i dont rly know how.

  1. Update windows install all updates.
  2. https://www.worldtimeserver.com/atomic-clock/
    • ping google.com
    • ping 8.8.8.8
    • ping time.windows.com
  3. https://www.youtube.com/watch?v=7KFJDFkiaAg

One ot this steps fix my issue in sync time.

Rohianon commented 12 months ago

In my case I'm running WSL2 with Ubuntu in my Windows 11 machine. When I checked the time in the ubuntu terminal (where the nextjs app is running) it was out of sync with Windows so I had to update it manually with the following command sudo hwclock -s. After that the problem was solved. I read that it's a common problem when the computer go to sleep, the Ubuntu clock gets out of sync with Windows.

Resolved my isssue clearly. Thanks

bhaski2003 commented 12 months ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

  • Click on "Settings" in the Windows Start menu.
  • Navigate to "Time & Language" within the Settings menu.
  • Select "Date & Time" from the Time & Language options.
  • Click on "Additional Settings."
  • Finally, select "Sync now" to synchronize your system's date and time settings.

image

This fixed my issue, You can give it a try.

thanks a tonn manhh

PhucHung2k1 commented 12 months ago

i can'f fix it. help me pls.. image

bhaski2003 commented 12 months ago

You should go to 'Date and time' settings on windows and there 'Sync now' If this doesn't work then , try turning off/on the 'set automatic time' and 'select automatic timezone' for both try turning off/on and try also with sync now :))

On Thu, 30 Nov, 2023, 1:39 pm PhucHung2k1, @.***> wrote:

i can'f fix it. help me pls.. image.png (view on web) https://github.com/adrianhajdin/threads/assets/124114709/4c96636b-81a6-4260-9d96-02e54e82d4fd

— Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/threads/issues/86#issuecomment-1833285285, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWZGTS5Y5T62AATOHBWQ4D3YHA5NFAVCNFSM6AAAAAA5KONN2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZTGI4DKMRYGU . You are receiving this because you commented.Message ID: @.***>

PhucHung2k1 commented 12 months ago

You should go to 'Date and time' settings on windows and there 'Sync now' If this doesn't work then , try turning off/on the 'set automatic time' and 'select automatic timezone' for both try turning off/on and try also with sync now :)) On Thu, 30 Nov, 2023, 1:39 pm PhucHung2k1, @.> wrote: i can'f fix it. help me pls.. image.png (view on web) https://github.com/adrianhajdin/threads/assets/124114709/4c96636b-81a6-4260-9d96-02e54e82d4fd — Reply to this email directly, view it on GitHub <#86 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWZGTS5Y5T62AATOHBWQ4D3YHA5NFAVCNFSM6AAAAAA5KONN2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZTGI4DKMRYGU . You are receiving this because you commented.Message ID: @.>

image it take long time and doesn't work again :((

bhaski2003 commented 12 months ago

Again try with sync now and also try different combinations of those above 2 options like set auto for both time and zones it worked fomme

On Thu, 30 Nov, 2023, 1:48 pm PhucHung2k1, @.***> wrote:

You should go to 'Date and time' settings on windows and there 'Sync now' If this doesn't work then , try turning off/on the 'set automatic time' and 'select automatic timezone' for both try turning off/on and try also with sync now :)) … <#m1441043557748212991> On Thu, 30 Nov, 2023, 1:39 pm PhucHung2k1, @.> wrote: i can'f fix it. help me pls.. image.png (view on web) https://github.com/adrianhajdin/threads/assets/124114709/4c96636b-81a6-4260-9d96-02e54e82d4fd https://github.com/adrianhajdin/threads/assets/124114709/4c96636b-81a6-4260-9d96-02e54e82d4fd — Reply to this email directly, view it on GitHub <#86 (comment) https://github.com/adrianhajdin/threads/issues/86#issuecomment-1833285285>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWZGTS5Y5T62AATOHBWQ4D3YHA5NFAVCNFSM6AAAAAA5KONN2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZTGI4DKMRYGU https://github.com/notifications/unsubscribe-auth/AWZGTS5Y5T62AATOHBWQ4D3YHA5NFAVCNFSM6AAAAAA5KONN2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZTGI4DKMRYGU . You are receiving this because you commented.Message ID: @.>

image.png (view on web) https://github.com/adrianhajdin/threads/assets/124114709/d3a786a4-7db3-4007-b449-7d8f37e64a26 it take long time and doesn't work again :((

— Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/threads/issues/86#issuecomment-1833296326, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWZGTS5PJWLI32MDFVNB7GTYHA6N7AVCNFSM6AAAAAA5KONN2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZTGI4TMMZSGY . You are receiving this because you commented.Message ID: @.***>

Ankitsharma991 commented 11 months ago

@FredDaFed sudo apt install ntpupdate && sudo ntpdate pool.ntp.org this command is not working, showing cannot locate packages for ntpupdate. So, can you share another way? for now, what i did to prevent this error is, i just delete my account relogin and use the tokens. and that's how it is working but the problem is till when i need to do like this only??

Aaryan123456679 commented 11 months ago

I am using Mac and facing this error what steps would work ?

bhaski2003 commented 11 months ago

Please refer my above instructions , prolly a mismatch btw time in ur system and time in server

Bright-200 commented 10 months ago

I change my localhost:3000 to another option such as localhost3001 and it worked.

hieupvXmasEve commented 10 months ago

Screenshot 2024-01-02 144436 I fixed it by turning everything on as in the picture and clicking "sync now".

Drake669 commented 10 months ago

If you are mac, you can go to your date and time settings and then check the box for "set date and time automatically" if its and unchecked and uncheck if its checked. This fixed it for me

ManuWeb3 commented 10 months ago

Found the issue with my system. My local instance of WSL Ubunbtu has a time lag of an hour. That's the reason it's getting messed up with the Clerk JWT token thing.

Now, I'm browing net/using ChatGPT to fix the time clock of WSL on my Windows system

ManuWeb3 commented 10 months ago

My issue resolved. Removed systemd-timesyncd and installed ntp. That synced my WSL time with the correct network time and I got rid of the error.

Elee-Lawleit commented 10 months ago

Does anyone know how to handle this error accurately on the application level? Does it appear in production?

moschan commented 10 months ago

Under the mac OS. I tried this command to force to sync my machine time.

sudo sntp -Ss time.asia.apple.com

Then issued fixed, for my case.

Danin1993 commented 10 months ago

Well i fix it but i dont rly know how.

  1. Update windows install all updates.
  2. https://www.worldtimeserver.com/atomic-clock/
  • ping google.com
  • ping 8.8.8.8
  • ping time.windows.com
  1. https://www.youtube.com/watch?v=7KFJDFkiaAg

One ot this steps fix my issue in sync time.

this actually fixed it for me

HugoFortunato commented 10 months ago

If you are using WSL with windows, it will be slightly off.

ISSUE: image

SOLUTION: If you go into your Ubuntu WSL terminal, the command below will fix the issue:

sudo apt install ntpupdate && sudo ntpdate pool.ntp.org

RESULTS: 9 Oct 06:46:10 ntpdate[31661]: step time server 129.250.35.250 offset +148.127650 sec Restart your server then it should work as seen below: image After Signing in and accessing secured page: image

Checking home page after signing in: image

You should to update your command to make it works on terminal:

your command: sudo apt install ntpupdate && sudo ntpdate pool.ntp.org

correct command: sudo apt install ntpdate && sudo ntpdate pool.ntp.org

Now, it works for me! Thank you.

devkypham commented 9 months ago

Update your system time like here https://time.is/, I updated and fixed the error

designbyhsn commented 9 months ago

If you are in Windows 11 try these steps

1: Sync your time from the settings 2: Restart your Pc 3: Run your app 4: Open the inspect panel in the browser 5: Switch to storage 6: Delete all from localhost

inspect

123Brijesh44aa commented 8 months ago

WORKING SOLUTION FOR WINDOWS :

Go To Services -> Windows Time -> Right click -> Start Again Go to Services -> Windows Time -> Right Click -> properties -> startup type -> automatic and then apply .

After that Go to Settings -> Date and Time -> Sync

aiyaruch1320 commented 8 months ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

  • Click on "Settings" in the Windows Start menu.
  • Navigate to "Time & Language" within the Settings menu.
  • Select "Date & Time" from the Time & Language options.
  • Click on "Additional Settings."
  • Finally, select "Sync now" to synchronize your system's date and time settings.

image

This fixed my issue, You can give it a try.

it's work! thank

harsh7800 commented 7 months ago

turning the "Set time Automatically" off worked for me :)

dejoma commented 7 months ago

I have this issue on Vercel... I deleted a user in Clerk auth, it was stored in the cookie and tried to use the cookie for logging in.

henriquedevelops commented 7 months ago

I get this error all the time, I usually speed up the timer and stop this error but I think it is something clerk is trying to fix

hey @MatthewAraujo , could you please tell what do you mean by "speed up the timer"?

thuongtruong1009 commented 6 months ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

  • Click on "Settings" in the Windows Start menu.
  • Navigate to "Time & Language" within the Settings menu.
  • Select "Date & Time" from the Time & Language options.
  • Click on "Additional Settings."
  • Finally, select "Sync now" to synchronize your system's date and time settings.

image

This fixed my issue, You can give it a try.

thank you very much, It works for me! 💖

issam-seghir commented 5 months ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

  • Click on "Settings" in the Windows Start menu.
  • Navigate to "Time & Language" within the Settings menu.
  • Select "Date & Time" from the Time & Language options.
  • Click on "Additional Settings."
  • Finally, select "Sync now" to synchronize your system's date and time settings.

image

This fixed my issue, You can give it a try.

Oh man, you saved my day! Thank you so much! 🥳

Helloflixofficial commented 4 months ago

Here we go again. Thanks for your help, guys! For Windows:

augustojaba commented 3 months ago

If you are using WSL with windows, it will be slightly off.

ISSUE: image

SOLUTION: If you go into your Ubuntu WSL terminal, the command below will fix the issue:

sudo apt install ntpupdate && sudo ntpdate pool.ntp.org

RESULTS: 9 Oct 06:46:10 ntpdate[31661]: step time server 129.250.35.250 offset +148.127650 sec Restart your server then it should work as seen below: image After Signing in and accessing secured page: image

Checking home page after signing in: image

This solution worked to me. Thanks.

jlondonobo commented 3 months ago

user in Clerk auth, it was stored in the cookie

I have this issue on Vercel... I deleted a user in Clerk auth, it was stored in the cookie and tried to use the cookie for logging in.

Hey @dejoma, I’m running into the same ‘clock skew detected’ error on Vercel. Did you manage to find a fix? Could really use some help here!

dejoma commented 3 months ago

user in Clerk auth, it was stored in the cookie

I have this issue on Vercel... I deleted a user in Clerk auth, it was stored in the cookie and tried to use the cookie for logging in.

Hey @dejoma, I’m running into the same ‘clock skew detected’ error on Vercel. Did you manage to find a fix? Could really use some help here!

Delete the cookies, or you can write a temporary middleware solution where you find all users, even when logged in, in the clerk database and only then allow the request.

Abhay809 commented 2 months ago

If you are using Windows 11 and encountering an error, you can attempt to resolve it by following these steps:

  • Click on "Settings" in the Windows Start menu.
  • Navigate to "Time & Language" within the Settings menu.
  • Select "Date & Time" from the Time & Language options.
  • Click on "Additional Settings."
  • Finally, select "Sync now" to synchronize your system's date and time settings.

image

This fixed my issue, You can give it a try.

Issue fixed. this is helpful