Skip to content

Commit 25a73fb

Browse files
authored
feat(clerk-js,shared): Remove expired_token retry flow (#8108)
The previous session token is now always sent in the /tokens POST body (via the `token` param), so the backend no longer needs to request it via a 422 missing_expired_token error and retry. Removes: - MissingExpiredTokenError class and its re-export from @clerk/shared - The catch-and-retry logic in Session.#createTokenResolver - 4 related tests in Session.test.ts
1 parent 2fb8c5a commit 25a73fb

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Skip `expired_token` retry flow when Session Minter is enabled. When `sessionMinter` is on, the token is sent in the POST body, so the retry-with-expired-token fallback is unnecessary. The retry flow is preserved for non-Session Minter mode.

packages/clerk-js/src/core/resources/Session.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,20 @@ export class Session extends BaseResource implements SessionResource {
490490
organizationId: organizationId ?? null,
491491
...(sessionMinterEnabled && this.lastActiveToken ? { token: this.lastActiveToken.getRawString() } : {}),
492492
};
493-
const lastActiveToken = this.lastActiveToken?.getRawString();
494493

495-
const tokenResolver = Token.create(path, params, skipCache ? { debug: 'skip_cache' } : undefined).catch(e => {
494+
if (sessionMinterEnabled) {
495+
// Session Minter sends the token in the body, no expired_token retry needed
496+
return Token.create(path, params, skipCache ? { debug: 'skip_cache' } : undefined);
497+
}
498+
499+
// TODO: Remove this expired_token retry flow when the sessionMinter flag is removed
500+
const lastActiveToken = this.lastActiveToken?.getRawString();
501+
return Token.create(path, params, skipCache ? { debug: 'skip_cache' } : undefined).catch(e => {
496502
if (MissingExpiredTokenError.is(e) && lastActiveToken) {
497503
return Token.create(path, { ...params }, { expired_token: lastActiveToken });
498504
}
499505
throw e;
500506
});
501-
502-
return tokenResolver;
503507
}
504508

505509
#dispatchTokenEvents(token: TokenResource, shouldDispatch: boolean): void {

scripts/validate-staging-instances.test.mjs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ describe('collapseAttributeMismatches', () => {
229229
{ path: 'user_settings.attributes.phone_number.verifications', prod: ['phone_code'], staging: [] },
230230
];
231231
const result = collapseAttributeMismatches(mismatches);
232-
expect(result).toEqual([
233-
{ path: 'user_settings.attributes.phone_number.enabled', prod: true, staging: false },
234-
]);
232+
expect(result).toEqual([{ path: 'user_settings.attributes.phone_number.enabled', prod: true, staging: false }]);
235233
});
236234

237235
it('keeps child diffs when .enabled does NOT differ', () => {
@@ -286,9 +284,7 @@ describe('collapseSocialMismatches', () => {
286284
{ path: 'user_settings.social.google.strategy', prod: 'oauth_google', staging: undefined },
287285
];
288286
const result = collapseSocialMismatches(mismatches);
289-
expect(result).toEqual([
290-
{ path: 'user_settings.social.google', prod: { enabled: true }, staging: undefined },
291-
]);
287+
expect(result).toEqual([{ path: 'user_settings.social.google', prod: { enabled: true }, staging: undefined }]);
292288
});
293289

294290
it('collapses child diffs for extra social provider on staging', () => {
@@ -297,9 +293,7 @@ describe('collapseSocialMismatches', () => {
297293
{ path: 'user_settings.social.github.enabled', prod: undefined, staging: true },
298294
];
299295
const result = collapseSocialMismatches(mismatches);
300-
expect(result).toEqual([
301-
{ path: 'user_settings.social.github', prod: undefined, staging: { enabled: true } },
302-
]);
296+
expect(result).toEqual([{ path: 'user_settings.social.github', prod: undefined, staging: { enabled: true } }]);
303297
});
304298

305299
it('keeps child diffs when both prod and staging have the provider', () => {
@@ -313,9 +307,7 @@ describe('collapseSocialMismatches', () => {
313307
});
314308

315309
it('does not affect non-social mismatches', () => {
316-
const mismatches = [
317-
{ path: 'auth_config.session_token_ttl', prod: 3600, staging: 7200 },
318-
];
310+
const mismatches = [{ path: 'auth_config.session_token_ttl', prod: 3600, staging: 7200 }];
319311
const result = collapseSocialMismatches(mismatches);
320312
expect(result).toEqual(mismatches);
321313
});

0 commit comments

Comments
 (0)