Skip to content

Commit 83b6fa4

Browse files
nikosdouvlisLauraBeatris
authored andcommitted
Fix early returns in setActive
1 parent 98111bd commit 83b6fa4

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,8 +1311,7 @@ export class Clerk implements ClerkInterface {
13111311
newSession?.currentTask &&
13121312
this.#options.taskUrls?.[newSession?.currentTask.key];
13131313

1314-
const shouldNavigate = (redirectUrl || taskUrl || setActiveNavigate) && !beforeEmit;
1315-
if (shouldNavigate) {
1314+
if (!beforeEmit && (redirectUrl || taskUrl || setActiveNavigate)) {
13161315
await tracker.track(async () => {
13171316
if (!this.client) {
13181317
// Typescript is not happy because since thinks this.client might have changed to undefined because the function is asynchronous.
@@ -1328,28 +1327,18 @@ export class Clerk implements ClerkInterface {
13281327
? buildURL({ base: taskUrl, hashSearchParams: { redirectUrl } }, { stringify: true })
13291328
: taskUrl;
13301329
await this.navigate(taskUrlWithRedirect);
1331-
return;
1332-
}
1333-
1334-
if (setActiveNavigate && newSession) {
1330+
} else if (setActiveNavigate && newSession) {
13351331
await setActiveNavigate({ session: newSession });
1336-
return;
1337-
}
1338-
1339-
if (!redirectUrl) {
1340-
return;
1341-
}
1342-
1343-
if (!this.client.isEligibleForTouch()) {
1332+
} else if (redirectUrl) {
1333+
if (this.client.isEligibleForTouch()) {
1334+
const absoluteRedirectUrl = new URL(redirectUrl, window.location.href);
1335+
const redirectUrlWithAuth = this.buildUrlWithAuth(
1336+
this.client.buildTouchUrl({ redirectUrl: absoluteRedirectUrl }),
1337+
);
1338+
await this.navigate(redirectUrlWithAuth);
1339+
}
13441340
await this.navigate(redirectUrl);
1345-
return;
13461341
}
1347-
1348-
const absoluteRedirectUrl = new URL(redirectUrl, window.location.href);
1349-
const redirectUrlWithAuth = this.buildUrlWithAuth(
1350-
this.client.buildTouchUrl({ redirectUrl: absoluteRedirectUrl }),
1351-
);
1352-
await this.navigate(redirectUrlWithAuth);
13531342
});
13541343
}
13551344

0 commit comments

Comments
 (0)