-
Notifications
You must be signed in to change notification settings - Fork 431
feat(clerk-js): Improve getToken offline handling
#7598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bratsos
wants to merge
39
commits into
main
Choose a base branch
from
alexbratsos/user-4063-improve-gettoken-offline-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
b5f683d
feat(clerk-js): Stale-while-revalidate session token
jacekradko caa97e2
wip
jacekradko 3914ffa
Merge branch 'vincent-and-the-doctor' into feat/stale-while-revalidat…
jacekradko 8c4092f
add hard cutoff for background refresh
jacekradko ed58e71
Merge branch 'vincent-and-the-doctor' into feat/stale-while-revalidat…
jacekradko 460964c
capture tokenResolver reference before potential cache changes
jacekradko b3f14aa
preserver SWR semantics on concurrent getToken calls
jacekradko ea7b6ee
Merge branch 'vincent-and-the-doctor' into feat/stale-while-revalidat…
jacekradko d6dd49c
Use poller exlusively for refreshing tokens
jacekradko 1c722cf
Merge branch 'vincent-and-the-doctor' into feat/stale-while-revalidat…
jacekradko b1104ce
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko 7a92b1a
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko e73b5ff
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko 441532f
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko 9444dde
Merge main into feat/stale-while-revalidate-token
jacekradko c86f32e
chore: add changeset for stale-while-revalidate token
jacekradko a906a1f
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko f8460b2
Merge remote-tracking branch 'origin/main' into feat/stale-while-reva…
jacekradko bce3cae
feat(clerk-js): Add automatic background token refresh on SWR
jacekradko 1da9c8f
docs(upgrade): Add Core 3 documentation for token SWR behavior
jacekradko 11551e1
test(clerk-js): Add tests for refreshIfStale and leewayInSeconds options
jacekradko be63362
chore(clerk-js): Increase bundle size limit for SWR background refresh
jacekradko 6730e62
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko d2cac65
feat(clerk-js): Rename leewayInSeconds to backgroundRefreshThreshold
jacekradko e3a9a5a
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko 46b68ed
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko d5075a7
fix(clerk-js): use JWT iat for token cache timing to fix SWR threshol…
jacekradko ca53830
chore(clerk-js): add SWR debug logging for threshold investigation
jacekradko e8b375f
chore(clerk-js): enhance SWR debug logging for duplicate refresh inve…
jacekradko c58d1f4
chore(clerk-js): remove SWR investigation debug logging
jacekradko 96a5b68
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko cb291e7
feat(clerk-js): Replace SWR with event-driven token refresh
jacekradko e426411
fix: remove unused variable in Session tests
jacekradko 8c5c6e5
chore: update changeset for proactive token refresh
jacekradko 9ce6dd3
feat(clerk-js): Make leewayInSeconds configurable for proactive refresh
jacekradko 5d43ab3
chore: format
jacekradko 5ed81e8
Merge branch 'main' into feat/stale-while-revalidate-token
jacekradko 640e362
feat(clerk-js): Throw ClerkOfflineError from getToken() when offline
bratsos 9de4869
chore: add changeset
bratsos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/clerk-js': minor | ||
| --- | ||
|
|
||
| Add proactive session token refresh. Tokens are now automatically refreshed in the background before they expire. The `leewayInSeconds` option controls how far in advance refresh is triggered (default: 15 seconds, minimum: 5 seconds). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --- | ||
| '@clerk/tanstack-react-start': major | ||
| '@clerk/react-router': major | ||
| '@clerk/clerk-js': major | ||
| '@clerk/upgrade': major | ||
| '@clerk/nextjs': major | ||
| '@clerk/shared': major | ||
| '@clerk/react': major | ||
| '@clerk/nuxt': major | ||
| '@clerk/vue': major | ||
| --- | ||
|
|
||
| `getToken()` now throws `ClerkOfflineError` instead of returning `null` when the client is offline. | ||
|
|
||
| This makes it explicit that a token fetch failure was due to network conditions, not authentication state. Previously, returning `null` could be misinterpreted as "user is signed out," potentially causing the cached token to be cleared. | ||
|
|
||
| To handle this change, catch `ClerkOfflineError` from `getToken()` calls: | ||
|
|
||
| ```typescript | ||
| import { ClerkOfflineError } from '@clerk/react/errors'; | ||
|
|
||
| try { | ||
| const token = await session.getToken(); | ||
| } catch (error) { | ||
| if (ClerkOfflineError.is(error)) { | ||
| // Handle offline scenario - show offline UI, retry later, etc. | ||
| } | ||
| throw error; | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this should be a major change in all sdks 🤔