Skip to content

Commit 079614c

Browse files
committed
Fix withTaskGuard import path
1 parent 4766025 commit 079614c

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { withCardStateProvider } from '@/ui/elements/contexts';
88
import { useMultipleSessions } from '@/ui/hooks/useMultipleSessions';
99
import { useOrganizationListInView } from '@/ui/hooks/useOrganizationListInView';
1010

11-
import { withTaskGuard } from '../shared/withTaskGuard';
11+
import { withTaskGuard } from '../shared';
1212
import { ChooseOrganizationScreen } from './ChooseOrganizationScreen';
1313
import { CreateOrganizationScreen } from './CreateOrganizationScreen';
1414

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { handleError } from '@/ui/utils/errorHandler';
1414
import { createPasswordError } from '@/ui/utils/passwordUtils';
1515
import { useFormControl } from '@/ui/utils/useFormControl';
1616

17-
import { withTaskGuard } from '../shared/withTaskGuard';
17+
import { withTaskGuard } from '../shared';
1818

1919
const TaskResetPasswordInternal = () => {
2020
const clerk = useClerk();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { withTaskGuard } from './withTaskGuard';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { SessionTask } from '@clerk/shared/types';
2+
import type { ComponentType } from 'react';
3+
4+
import { warnings } from '@/core/warnings';
5+
import { withRedirect } from '@/ui/common';
6+
import { useSessionTasksContext } from '@/ui/contexts/components/SessionTasks';
7+
import type { AvailableComponentProps } from '@/ui/types';
8+
9+
export const withTaskGuard = <P extends AvailableComponentProps>(
10+
Component: ComponentType<P>,
11+
taskKey: SessionTask['key'],
12+
) => {
13+
const displayName = Component.displayName || Component.name || 'Component';
14+
Component.displayName = displayName;
15+
16+
const HOC = (props: P) => {
17+
const ctx = useSessionTasksContext();
18+
return withRedirect(
19+
Component,
20+
clerk => !clerk.session?.currentTask || clerk.session.currentTask.key !== taskKey,
21+
({ clerk }) =>
22+
!clerk.session ? clerk.buildSignInUrl() : (ctx.redirectUrlComplete ?? clerk.buildAfterSignInUrl()),
23+
warnings.cannotRenderComponentWhenTaskDoesNotExist,
24+
)(props);
25+
};
26+
27+
HOC.displayName = `withTaskGuard(${displayName})`;
28+
29+
return HOC;
30+
};

0 commit comments

Comments
 (0)