Skip to content

Commit 51cf079

Browse files
committed
refactor(clerk-js): collapse degraded recovery to one updateClient
Compute the recovery jwt once (minted when a session exists, else the cookie) and build the client from it in a single place, instead of duplicating updateClient(createClientFromJwt(...)) across both branches.
1 parent bb57007 commit 51cf079

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,18 +3273,15 @@ export class Clerk implements ClerkInterface {
32733273

32743274
try {
32753275
const session = this.#defaultSession(createClientFromJwt(this.#authService?.getSessionCookie()));
3276-
3277-
if (session) {
3278-
// Prefer minting a fresh token as its claims are fresher than the cookie's
3279-
session.clearCache();
3280-
const jwt = await timeLimit(session.getToken(), INITIALIZATION_TIMEOUT_MS).catch(() => {
3281-
session.clearCache();
3282-
return this.#authService?.getSessionCookie();
3283-
});
3284-
this.updateClient(createClientFromJwt(jwt));
3285-
} else {
3286-
this.updateClient(createClientFromJwt(this.#authService?.getSessionCookie()));
3287-
}
3276+
// Prefer minting a fresh token as its claims are fresher than the cookie's
3277+
session?.clearCache();
3278+
const jwt = session
3279+
? await timeLimit(session.getToken(), INITIALIZATION_TIMEOUT_MS).catch(() => {
3280+
session.clearCache();
3281+
return this.#authService?.getSessionCookie();
3282+
})
3283+
: this.#authService?.getSessionCookie();
3284+
this.updateClient(createClientFromJwt(jwt));
32883285
} finally {
32893286
this.#authService?.startPollingForToken();
32903287
}

0 commit comments

Comments
 (0)