Skip to content

chore(clerk-js): Improve Token.create to handle error due to network failure - #3068

Merged
dimkl merged 1 commit into
release/v4from
fix/token-refresh-failed-nul
Mar 29, 2024
Merged

chore(clerk-js): Improve Token.create to handle error due to network failure#3068
dimkl merged 1 commit into
release/v4from
fix/token-refresh-failed-nul

Conversation

@dimkl

Copy link
Copy Markdown
Contributor

Description

Error resolved by returning an empty string or null instead of trying to decode the jwt property from the response data. After this fix an token.getRawString() will return an empty string and session.getToken() will return null on Network failure and when request fails and browser is offline.

Current error message example:

Error: ClerkJS: Token refresh failed (error='Cannot read properties of null (reading 'jwt')')

Backport: #3035

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@dimkl
dimkl requested a review from nikosdouvlisMarch 29, 2024 10:37
@dimkldimkl self-assigned this Mar 29, 2024
@dimkl
dimkl requested a review from a team as a code ownerMarch 29, 2024 10:37
@changeset-bot

changeset-botBot commented Mar 29, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2580596

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
NameType
@clerk/clerk-jsPatch
@clerk/typesPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch
@clerk/backendPatch
@clerk/fastifyPatch
gatsby-plugin-clerkPatch
@clerk/localizationsPatch
@clerk/nextjsPatch
@clerk/clerk-reactPatch
@clerk/remixPatch
@clerk/clerk-sdk-nodePatch
@clerk/themesPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dimkl

Copy link
Copy Markdown
ContributorAuthor

!snapshot

@dimkl
dimklforce-pushed the fix/token-refresh-failed-nul branch from eb4f14c to 2063010CompareMarch 29, 2024 11:41
@clerk-cookie

Copy link
Copy Markdown
Collaborator

Hey @dimkl - the snapshot version command generated the following package versions:

PackageVersion
@clerk/backend0.38.4-snapshot.veb4f14c
@clerk/chrome-extension0.6.17-snapshot.veb4f14c
@clerk/clerk-js4.70.7-snapshot.veb4f14c
@clerk/clerk-expo0.20.12-snapshot.veb4f14c
@clerk/fastify0.6.37-snapshot.veb4f14c
gatsby-plugin-clerk4.4.39-snapshot.veb4f14c
@clerk/localizations1.26.17-snapshot.veb4f14c
@clerk/nextjs4.29.10-snapshot.veb4f14c
@clerk/clerk-react4.30.8-snapshot.veb4f14c
@clerk/remix3.2.1-snapshot.veb4f14c
@clerk/clerk-sdk-node4.13.12-snapshot.veb4f14c
@clerk/themes1.7.11-snapshot.veb4f14c
@clerk/types3.62.2-snapshot.veb4f14c

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/backend

npm i @clerk/backend@0.38.4-snapshot.veb4f14c --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@0.6.17-snapshot.veb4f14c --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@4.70.7-snapshot.veb4f14c --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@0.20.12-snapshot.veb4f14c --save-exact

@clerk/fastify

npm i @clerk/fastify@0.6.37-snapshot.veb4f14c --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@4.4.39-snapshot.veb4f14c --save-exact

@clerk/localizations

npm i @clerk/localizations@1.26.17-snapshot.veb4f14c --save-exact

@clerk/nextjs

npm i @clerk/nextjs@4.29.10-snapshot.veb4f14c --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@4.30.8-snapshot.veb4f14c --save-exact

@clerk/remix

npm i @clerk/remix@3.2.1-snapshot.veb4f14c --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@4.13.12-snapshot.veb4f14c --save-exact

@clerk/themes

npm i @clerk/themes@1.7.11-snapshot.veb4f14c --save-exact

@clerk/types

npm i @clerk/types@3.62.2-snapshot.veb4f14c --save-exact

@dimkl
dimklforce-pushed the fix/token-refresh-failed-nul branch from 2063010 to deb94e2CompareMarch 29, 2024 11:47
@dimkl

Copy link
Copy Markdown
ContributorAuthor

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

Hey @dimkl - the snapshot version command generated the following package versions:

PackageVersion
@clerk/backend0.38.4-snapshot.vdeb94e2
@clerk/chrome-extension0.6.17-snapshot.vdeb94e2
@clerk/clerk-js4.70.7-snapshot.vdeb94e2
@clerk/clerk-expo0.20.12-snapshot.vdeb94e2
@clerk/fastify0.6.37-snapshot.vdeb94e2
gatsby-plugin-clerk4.4.39-snapshot.vdeb94e2
@clerk/localizations1.26.17-snapshot.vdeb94e2
@clerk/nextjs4.29.10-snapshot.vdeb94e2
@clerk/clerk-react4.30.8-snapshot.vdeb94e2
@clerk/remix3.2.1-snapshot.vdeb94e2
@clerk/clerk-sdk-node4.13.12-snapshot.vdeb94e2
@clerk/themes1.7.11-snapshot.vdeb94e2
@clerk/types3.62.2-snapshot.vdeb94e2

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/backend

npm i @clerk/backend@0.38.4-snapshot.vdeb94e2 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@0.6.17-snapshot.vdeb94e2 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@4.70.7-snapshot.vdeb94e2 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@0.20.12-snapshot.vdeb94e2 --save-exact

@clerk/fastify

npm i @clerk/fastify@0.6.37-snapshot.vdeb94e2 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@4.4.39-snapshot.vdeb94e2 --save-exact

@clerk/localizations

npm i @clerk/localizations@1.26.17-snapshot.vdeb94e2 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@4.29.10-snapshot.vdeb94e2 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@4.30.8-snapshot.vdeb94e2 --save-exact

@clerk/remix

npm i @clerk/remix@3.2.1-snapshot.vdeb94e2 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@4.13.12-snapshot.vdeb94e2 --save-exact

@clerk/themes

npm i @clerk/themes@1.7.11-snapshot.vdeb94e2 --save-exact

@clerk/types

npm i @clerk/types@3.62.2-snapshot.vdeb94e2 --save-exact

…failure
Error resolved by returning an empty string or null instead of trying to
decode the `jwt` property from the response data. After this fix an
`token.getRawString()` will return an empty string and `session.getToken()`
will return `null` on Network failure and when request fails and browser
is offline.
Current error message example:
```
Error: ClerkJS: Token refresh failed (error='Cannot read properties of null (reading 'jwt')')
```
@dimkl
dimklforce-pushed the fix/token-refresh-failed-nul branch from deb94e2 to 2580596CompareMarch 29, 2024 11:59

@brkalowbrkalow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@dimkl
dimkl merged commit cd2bf9d into release/v4Mar 29, 2024
@dimkl
dimkl deleted the fix/token-refresh-failed-nul branch March 29, 2024 16:24
@clerk-cookieclerk-cookie mentioned this pull request Mar 29, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@dimkl@clerk-cookie@brkalow