Skip to content

Commit 64ab4ae

Browse files
committed
revert(clerk-js): drop Session.ts monotonic guards
The Session.ts guards at #_getToken cache-hit emit and #dispatchTokenEvents were suppressing token:update events that AuthCookieService needs to write the session cookie. Backend then saw an empty/stale cookie and treated the session as unauthenticated. Keep only the broadcast handler guard in tokenCache.ts, which covers the original motivation: cross-tab races where a background tab's stale edge-minted token can clobber a fresher DB-minted token via the BroadcastChannel.
1 parent 7efa1af commit 64ab4ae

2 files changed

Lines changed: 2 additions & 13 deletions

File tree

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import type {
4242
} from '@clerk/shared/types';
4343
import { isWebAuthnSupported as isWebAuthnSupportedOnWindow } from '@clerk/shared/webauthn';
4444

45-
import { pickFreshestJwt } from '@/core/tokenFreshness';
4645
import { unixEpochToDate } from '@/utils/date';
4746
import { debugLogger } from '@/utils/debug';
4847
import { TokenId } from '@/utils/tokenId';
@@ -459,11 +458,7 @@ export class Session extends BaseResource implements SessionResource {
459458
// Only emit token updates when we have an actual token — emitting with an empty
460459
// token causes AuthCookieService to remove the __session cookie (looks like sign-out).
461460
if (shouldDispatchTokenUpdate && cachedToken.getRawString()) {
462-
const isStaler =
463-
this.lastActiveToken && pickFreshestJwt(this.lastActiveToken, cachedToken) === this.lastActiveToken;
464-
if (!isStaler) {
465-
eventBus.emit(events.TokenUpdate, { token: cachedToken });
466-
}
461+
eventBus.emit(events.TokenUpdate, { token: cachedToken });
467462
}
468463
result = cachedToken.getRawString() || null;
469464
} else if (!isBrowserOnline()) {
@@ -523,10 +518,6 @@ export class Session extends BaseResource implements SessionResource {
523518
return;
524519
}
525520

526-
if (this.lastActiveToken && pickFreshestJwt(this.lastActiveToken, token) === this.lastActiveToken) {
527-
return;
528-
}
529-
530521
eventBus.emit(events.TokenUpdate, { token });
531522

532523
if (token.jwt) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ describe('Session', () => {
9898
expect(BaseResource.clerk.getFapiClient().request).not.toHaveBeenCalled();
9999

100100
expect(token).toEqual(mockJwt);
101-
// Cache hits with the same token as lastActiveToken suppress re-emission
102-
// to avoid unnecessary cookie writes (monotonic freshness guard).
103-
expect(dispatchSpy).toHaveBeenCalledTimes(0);
101+
expect(dispatchSpy).toHaveBeenCalledTimes(2);
104102
});
105103

106104
it('returns same token without API call when Session is reconstructed', async () => {

0 commit comments

Comments
 (0)