Skip to content

Commit e5cb99b

Browse files
committed
Use taskUrl from AIOs navigation
1 parent d34616a commit e5cb99b

File tree

7 files changed

+14
-7
lines changed

7 files changed

+14
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,7 @@ export class Clerk implements ClerkInterface {
19291929
return this.setActive({
19301930
session: su.sessionId,
19311931
redirectUrl: redirectUrls.getAfterSignUpUrl(),
1932+
onPendingSession,
19321933
});
19331934
}
19341935

@@ -1953,6 +1954,7 @@ export class Clerk implements ClerkInterface {
19531954
return this.setActive({
19541955
session: sessionId,
19551956
redirectUrl: redirectUrls.getAfterSignInUrl(),
1957+
onPendingSession,
19561958
});
19571959
}
19581960
}

packages/clerk-js/src/ui/components/SessionTasks/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ const SessionTasksStart = () => {
2727
const currentTaskKey = clerk.session?.currentTask?.key;
2828
if (!currentTaskKey) return;
2929

30-
void navigate(`./${INTERNAL_SESSION_TASK_ROUTE_BY_KEY[currentTaskKey]}`);
30+
void navigate(
31+
clerk.__internal_getOption('taskUrls')?.[currentTaskKey] ??
32+
`./${INTERNAL_SESSION_TASK_ROUTE_BY_KEY[currentTaskKey]}`,
33+
);
3134
}, 500);
3235
return () => clearTimeout(timeoutId);
3336
}, [navigate, clerk, redirectUrlComplete]);

packages/clerk-js/src/ui/components/SessionTasks/tasks/TaskChooseOrganization/ChooseOrganizationScreen.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export const ChooseOrganizationScreen = withCardStateProvider(
9797

9898
const MembershipPreview = withCardStateProvider((props: { organization: OrganizationResource }) => {
9999
const card = useCardState();
100-
101100
const { redirectUrlComplete } = useSessionTasksContext();
102101
const { isLoaded, setActive } = useOrganizationList();
103102

packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ function SignInStartInternal(): JSX.Element {
199199
}
200200
}, [identifierField.value, identifierAttributes]);
201201

202-
// TODO -> Maybe navigate on a effect here?
203202
useEffect(() => {
204203
if (!organizationTicket) {
205204
return;

packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type UseMultisessionActionsParams = {
2121
} & Pick<UserButtonProps, 'userProfileMode' | 'appearance' | 'userProfileProps'>;
2222

2323
export const useMultisessionActions = (opts: UseMultisessionActionsParams) => {
24-
const { setActive, signOut, openUserProfile } = useClerk();
24+
const { setActive, signOut, openUserProfile, __internal_getOption } = useClerk();
2525
const card = useCardState();
2626
const { signedInSessions, otherSessions } = useMultipleSessions({ user: opts.user });
2727
const { navigate } = useRouter();
@@ -80,7 +80,7 @@ export const useMultisessionActions = (opts: UseMultisessionActionsParams) => {
8080
await navigateToTask(session, {
8181
baseUrl: displayConfig.signInUrl,
8282
navigate: navigate,
83-
// TODO -> Pass `clerk` into callback so we can access the taskUrls here
83+
options: { taskUrls: __internal_getOption('taskUrls') },
8484
});
8585
},
8686
}).finally(() => {

packages/clerk-js/src/ui/contexts/components/SignUp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ export const useSignUpContext = (): SignUpContextType => {
117117

118118
const onPendingSession: OnPendingSessionFn = async ({ session }) => {
119119
const currentTaskKey = session.currentTask.key;
120+
const customTaskUrl = clerk.__internal_getOption('taskUrls')?.[currentTaskKey];
120121

121122
switch (currentTaskKey) {
122123
case 'choose-organization': {
123-
await navigate(`../tasks/${currentTaskKey}`);
124+
await navigate(customTaskUrl ?? `../tasks/${currentTaskKey}`);
124125
}
125126
}
126127
};

packages/types/src/clerk.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ export type ClerkOptions = ClerkOptionsNavigation &
10711071
taskUrls?: Record<SessionTask['key'], string>;
10721072

10731073
/**
1074-
* Event handler for session transitions to `pending`
1074+
* Event handler called when a session transitions to `pending` status after successful sign-in.
10751075
*/
10761076
onPendingSession?: OnPendingSessionFn;
10771077
};
@@ -1199,6 +1199,9 @@ export type SetActiveParams = {
11991199
*/
12001200
redirectUrl?: string;
12011201

1202+
/**
1203+
* Event handler called when a session transitions to `pending` status after successful sign-in.
1204+
*/
12021205
onPendingSession?: OnPendingSessionFn;
12031206
};
12041207

0 commit comments

Comments
 (0)