javascript: ClerkJS: Token refresh failed. TypeError: Failed to fetch. Please try again.
- Review the documentation: https://clerk.com/docs
- Search for existing issues: https://github.com/clerkinc/javascript/issues
- Go through package changelog files.
- Provide the Frontend API key from your application dashboard.
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_Y2xlcmsudGVhbS1ncHQuY29tJA
Package + Version
-
@clerk/clerk-js -
@clerk/clerk-react -
@clerk/nextjs-4.23.2 -
@clerk/remix -
@clerk/types-3.49.0 -
@clerk/themes-1.7.5 -
@clerk/localizations -
@clerk/clerk-expo -
@clerk/backend-0.27.0 -
@clerk/clerk-sdk-node -
@clerk/shared -
@clerk/fastify -
@clerk/chrome-extension -
gatsby-plugin-clerk -
build/tooling/chore - other:
Dependencies + versions
Provide a json with the dependencies used in your project (copy paste from yarn.lock / package-lock.json) or a github project / template that reproduces the issue.
Include the @clerk/ packages and their versions!*
Example:
{
"dependencies": {
"react": "18.2.0",
"react-dom": "18.2.0",
"next": "13.4.16",
"axios": "^1.4.0",
"@clerk/backend": "0.27.0",
"@clerk/nextjs": "^4.23.2",
"@clerk/themes": "1.7.5",
"@clerk/types": "3.49.0",
"@sentry/core": "^7.64.0",
"@sentry/nextjs": "^7.64.0",
"@sentry/node": "^7.64.0",
"@sentry/profiling-node": "^1.1.2",
"@sentry/utils": "^7.64.0"
}
}
Browser/OS
If applicable e.g. Chrome {version}, Node {version} , Bun {version} , Cloudflare worker {version}
Description
We’re experiencing a severe number of errors reported by Sentry regarding the Clerk user authentication. It happens ad-hoc and between releases.
Error
ClerkJS: Token refresh failed (error='ClerkJS: Network error at "https://clerk.our-domain.com/v1/client/sessions/sess_2TwhWEx3j9IvWXU0qOtEwutNLx2/tokens?_clerk_js_version=4.53.0" - TypeError: Failed to fetch. Please try again.')
Is there anything we can do to improve this process and reduce the errors for our customers?
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 3
- Comments: 19 (5 by maintainers)
@jescalan As a developer, I will try to describe how to reproduce as best as I can.
The next few steps are Pure theories, guesses. I suspect one of them is why I have seen this error twice in the last three days.
Next time I encounter this error I will share the HAR file.
I work from several cafe’s during the day for fun while coding, and I don’t consistently get the error even then, so please remember the above is just my best guesses.
Hey everyone - we’re sorry that this is a frustrating error. We have discussed this as a team on several occasions, it’s a generic network error that can happen for a variety of reasons, and is very difficult for us to look into without a way to consistently reproduce it. We’re going to leave this issue open for now in case anyone is able to find a way to reproduce, but want to note that we aren’t actively working on it.
If anyone is able to produce a reproduction or is aiming to do so, this guide would maybe be helpful - alternately if it can be captured via replay that would be very useful as well.
I also have “Failed to fetch problem”
Solved it by downgrade to “@clerk/nextjs”: “4.21.13”,
Hey - Did anyone in here get to the bottom of this?
I agree with @saahirfoux that it’s a timeout of sorts. If I leave a browser tab open and come back a few hours later there is an error waiting for me
Error: ClerkJS: Token refresh failed (error='Cannot read properties of null (reading 'jwt')')I understand it’s hard to replicate to fix but can you give any guidance on how I can catch it?
Here’s an example from production. I had a tab in the background for a bit. Clerk requests a new token twice, then the third time fails, which causes the next time we request resources to fail, and for the page to crash because resources got 401 response codes.
@dimkl there were no cors errors This is the full error (abstracted our domain). What is HAR? does below help?
This is not related to a firefox add on so https://github.com/JakeChampion/fetch/issues/310 doesn’t seem related
Hello @Andriy-Kulak, Are you getting a
Token refresh failed ... TypeError: NetworkError ...or is it another type of token refresh failed issue? There are multiple token refresh failed errors.The above error is related to a NetworkError which may be caused by :
ref: https://github.com/JakeChampion/fetch/issues/310
Is it possible to have any of the following information:
cc: @tmcw , @kachar
@jescalan - we are getting a token refresh issue as well. it’s a bad issue because the client essentially is locked out from the website and has to change browsers or clear cache. can you please look into this?
It’s not acceptable for customers to be dealing with this & I see the same sentry errors as @tmcw . I unfortunately cannot recreate this issue locally.
I can confirm that this is not a bot issue - we get it on a variety of browsers, and for logged-in users in Sentry: