Skip to content

Commit 98111bd

Browse files
nikosdouvlisLauraBeatris
authored andcommitted
Always use the latest session for status checks
1 parent 249d366 commit 98111bd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import type {
2828
AuthenticateWithGoogleOneTapParams,
2929
AuthenticateWithMetamaskParams,
3030
AuthenticateWithOKXWalletParams,
31-
Clerk as ClerkInterface,
3231
ClerkAPIError,
3332
ClerkAuthenticateWithWeb3Params,
33+
Clerk as ClerkInterface,
3434
ClerkOptions,
3535
ClientJSONSnapshot,
3636
ClientResource,
@@ -1233,9 +1233,7 @@ export class Clerk implements ClerkInterface {
12331233
: noop;
12341234

12351235
let newSession = session === undefined ? this.session : session;
1236-
const sessionIsPending = newSession?.status === 'pending';
1237-
1238-
if (sessionIsPending) {
1236+
if (newSession?.status === 'pending') {
12391237
warnMissingPendingTaskHandlers({ ...this.#options, ...params });
12401238
}
12411239

@@ -1309,7 +1307,10 @@ export class Clerk implements ClerkInterface {
13091307
}
13101308

13111309
const taskUrl =
1312-
sessionIsPending && newSession?.currentTask && this.#options.taskUrls?.[newSession?.currentTask.key];
1310+
newSession?.status === 'pending' &&
1311+
newSession?.currentTask &&
1312+
this.#options.taskUrls?.[newSession?.currentTask.key];
1313+
13131314
const shouldNavigate = (redirectUrl || taskUrl || setActiveNavigate) && !beforeEmit;
13141315
if (shouldNavigate) {
13151316
await tracker.track(async () => {
@@ -1318,7 +1319,7 @@ export class Clerk implements ClerkInterface {
13181319
return;
13191320
}
13201321

1321-
if (!sessionIsPending) {
1322+
if (newSession?.status !== 'pending') {
13221323
this.#setTransitiveState();
13231324
}
13241325

@@ -1361,7 +1362,8 @@ export class Clerk implements ClerkInterface {
13611362
this.#emit();
13621363

13631364
// Do not revalidate server cache for pending sessions to avoid unmount of `SignIn/SignUp` AIOs when navigating to task
1364-
if (!sessionIsPending || newSession?.status === 'active') {
1365+
// newSession can be mutated by the time we get here (org change session touch)
1366+
if (newSession?.status !== 'pending') {
13651367
await onAfterSetActive();
13661368
}
13671369
} finally {

0 commit comments

Comments
 (0)