Skip to content

Commit 58fbac9

Browse files
brkalowclaude
andcommitted
refactor(clerk-js): Simplify _getToken control flow and trim comment
Flatten nested if/else in _getToken to make the three branches (cache hit / offline / fetch) equal peers. Trim redundant comment in #fetchToken. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2c09e1e commit 58fbac9

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,9 @@ export class Session extends BaseResource implements SessionResource {
456456
eventBus.emit(events.TokenUpdate, { token: cachedToken });
457457
}
458458
result = cachedToken.getRawString() || null;
459+
} else if (!isBrowserOnline()) {
460+
throw new ClerkRuntimeError('Browser is offline, skipping token fetch', { code: 'network_error' });
459461
} else {
460-
if (!isBrowserOnline()) {
461-
throw new ClerkRuntimeError('Browser is offline, skipping token fetch', { code: 'network_error' });
462-
}
463462
result = await this.#fetchToken(template, organizationId, tokenId, shouldDispatchTokenUpdate, skipCache);
464463
}
465464

@@ -530,8 +529,7 @@ export class Session extends BaseResource implements SessionResource {
530529
return tokenResolver.then(token => {
531530
const rawString = token.getRawString();
532531
if (!rawString) {
533-
// Token fetch returned an empty response — this happens when _baseFetch returns null
534-
// due to a network error while offline. Throw so retry logic in getToken() can handle it,
532+
// Throw so retry logic in getToken() can handle it,
535533
// rather than silently returning null (which callers interpret as "signed out").
536534
throw new ClerkRuntimeError('Token fetch returned empty response', { code: 'network_error' });
537535
}

0 commit comments

Comments
 (0)