File tree Expand file tree Collapse file tree 4 files changed +33
-2
lines changed
packages/clerk-js/src/ui/components/SessionTasks/tasks Expand file tree Collapse file tree 4 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { withCardStateProvider } from '@/ui/elements/contexts';
88import { useMultipleSessions } from '@/ui/hooks/useMultipleSessions' ;
99import { useOrganizationListInView } from '@/ui/hooks/useOrganizationListInView' ;
1010
11- import { withTaskGuard } from '../shared/withTaskGuard ' ;
11+ import { withTaskGuard } from '../shared' ;
1212import { ChooseOrganizationScreen } from './ChooseOrganizationScreen' ;
1313import { CreateOrganizationScreen } from './CreateOrganizationScreen' ;
1414
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import { handleError } from '@/ui/utils/errorHandler';
1414import { createPasswordError } from '@/ui/utils/passwordUtils' ;
1515import { useFormControl } from '@/ui/utils/useFormControl' ;
1616
17- import { withTaskGuard } from '../shared/withTaskGuard ' ;
17+ import { withTaskGuard } from '../shared' ;
1818
1919const TaskResetPasswordInternal = ( ) => {
2020 const clerk = useClerk ( ) ;
Original file line number Diff line number Diff line change 1+ export { withTaskGuard } from './withTaskGuard' ;
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments