Skip to content

Commit e5797d0

Browse files
committed
Add warning for missing params for task handling
1 parent 76c85b0 commit e5797d0

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ import {
151151
Organization,
152152
Waitlist,
153153
} from './resources/internal';
154-
import { navigateIfTaskExists } from './sessionTasks';
154+
import { navigateIfTaskExists, warnMissingPendingTaskHandlers } from './sessionTasks';
155155
import { State } from './state';
156156
import { warnings } from './warnings';
157157

@@ -1231,6 +1231,10 @@ export class Clerk implements ClerkInterface {
12311231
let newSession = session === undefined ? this.session : session;
12321232
const sessionIsPending = newSession?.status === 'pending';
12331233

1234+
if (sessionIsPending) {
1235+
warnMissingPendingTaskHandlers(params);
1236+
}
1237+
12341238
// At this point, the `session` variable should contain either an `SignedInSessionResource`
12351239
// ,`null` or `undefined`.
12361240
// We now want to set the last active organization id on that session (if it exists).

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { SessionResource, SessionTask } from '@clerk/types';
1+
import { logger } from '@clerk/shared/logger';
2+
import type { ClerkOptions, SessionResource, SessionTask, SetActiveParams } from '@clerk/types';
23

34
import { buildURL } from '../utils';
45

@@ -42,3 +43,19 @@ export function navigateIfTaskExists(
4243

4344
return navigate(buildTaskURL(currentTask, { base: baseUrl }));
4445
}
46+
47+
export function warnMissingPendingTaskHandlers(options: Record<string, unknown>) {
48+
const taskOptions = ['taskUrls', 'navigate'] as Array<
49+
keyof (Pick<SetActiveParams, 'navigate'> & Pick<ClerkOptions, 'taskUrls'>)
50+
>;
51+
52+
const hasAtLeastOneTaskOption = Object.keys(options).some(option => taskOptions.includes(option as any));
53+
if (hasAtLeastOneTaskOption) {
54+
return;
55+
}
56+
57+
// TODO - Link to after-auth docs once it gets released
58+
logger.warnOnce(
59+
`Clerk: Session has pending tasks but no handling is configured. To handle pending tasks automatically, provide either "taskUrls" for navigation to custom URLs or "navigate" for programmatic navigation. Without these options, users may get stuck on incomplete flows.`,
60+
);
61+
}

packages/clerk-js/src/utils/assertNoLegacyProp.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { logger } from '@clerk/shared/logger';
2-
import type { ClerkOptions } from '@clerk/types';
32

43
export function assertNoLegacyProp(props: Record<string, any>) {
54
const legacyProps = ['redirectUrl', 'afterSignInUrl', 'afterSignUpUrl', 'after_sign_in_url', 'after_sign_up_url'];
@@ -24,17 +23,3 @@ export function warnForNewPropShadowingLegacyProp(
2423
);
2524
}
2625
}
27-
28-
export function warnNoTaskOptions(options: ClerkOptions) {
29-
const taskOptions = ['taskUrls', 'onPendingSession'];
30-
31-
const hasAtLeastOneTaskOption = Object.keys(options).some(option => taskOptions.includes(option));
32-
if (hasAtLeastOneTaskOption) {
33-
return;
34-
}
35-
36-
logger.warnOnce(
37-
// TODO - Link to after-auth docs once it gets released
38-
`Clerk: After-auth is enabled and no task options configured. Consider providing "taskUrls" or "onPendingSession" to handle pending session tasks.`,
39-
);
40-
}

0 commit comments

Comments
 (0)