Skip to content

Commit 77d5f09

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 77d5f09

3 files changed

Lines changed: 38 additions & 13 deletions

File tree

.husky/_/husky.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env sh
2+
if [ -z "$husky_skip_init" ]; then
3+
debug () {
4+
if [ "$HUSKY_DEBUG" = "1" ]; then
5+
echo "husky (debug) - $1"
6+
fi
7+
}
8+
9+
readonly hook_name="$(basename -- "$0")"
10+
debug "starting $hook_name..."
11+
12+
if [ "$HUSKY" = "0" ]; then
13+
debug "HUSKY env variable is set to 0, skipping hook"
14+
exit 0
15+
fi
16+
17+
if [ -f ~/.huskyrc ]; then
18+
debug "sourcing ~/.huskyrc"
19+
. ~/.huskyrc
20+
fi
21+
22+
readonly husky_skip_init=1
23+
export husky_skip_init
24+
sh -e "$0" "$@"
25+
exitCode="$?"
26+
27+
if [ $exitCode != 0 ]; then
28+
echo "husky - $hook_name hook exited with code $exitCode (error)"
29+
fi
30+
31+
if [ $exitCode = 127 ]; then
32+
echo "husky - command not found in PATH=$PATH"
33+
fi
34+
35+
exit $exitCode
36+
fi

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)