Skip to content

Commit f6375f0

Browse files
authored
chore(clerk-react,vue,nextjs): Introduce <RedirectToTask /> component (#6416)
1 parent d4d2612 commit f6375f0

File tree

9 files changed

+43
-0
lines changed

9 files changed

+43
-0
lines changed

.changeset/slick-suns-hammer.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/nextjs': minor
3+
'@clerk/clerk-react': minor
4+
'@clerk/vue': minor
5+
---
6+
7+
Introduce `<RedirectToTask />` component

packages/nextjs/src/client-boundary/controlComponents.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export {
1010
Protect,
1111
RedirectToSignIn,
1212
RedirectToSignUp,
13+
RedirectToTask,
1314
RedirectToUserProfile,
1415
AuthenticateWithRedirectCallback,
1516
RedirectToCreateOrganization,

packages/nextjs/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export {
1212
RedirectToOrganizationProfile,
1313
RedirectToSignIn,
1414
RedirectToSignUp,
15+
RedirectToTask,
1516
RedirectToUserProfile,
1617
} from './client-boundary/controlComponents';
1718

packages/react-router/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports[`root public exports > should not change unexpectedly 1`] = `
2020
"RedirectToOrganizationProfile",
2121
"RedirectToSignIn",
2222
"RedirectToSignUp",
23+
"RedirectToTask",
2324
"RedirectToUserProfile",
2425
"SignIn",
2526
"SignInButton",

packages/react/src/components/controlComponents.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ export const RedirectToSignUp = withClerk(({ clerk, ...props }: WithClerkProp<Re
166166
return null;
167167
}, 'RedirectToSignUp');
168168

169+
export const RedirectToTask = withClerk(({ clerk }: WithClerkProp) => {
170+
const { session } = clerk;
171+
172+
React.useEffect(() => {
173+
if (!session) {
174+
void clerk.redirectToSignIn();
175+
return;
176+
}
177+
178+
void clerk.__internal_navigateToTaskIfAvailable();
179+
}, []);
180+
181+
return null;
182+
}, 'RedirectToTask');
183+
169184
/**
170185
* @function
171186
* @deprecated Use [`redirectToUserProfile()`](https://clerk.com/docs/references/javascript/clerk#redirect-to-user-profile) instead.

packages/react/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525
RedirectToOrganizationProfile,
2626
RedirectToSignIn,
2727
RedirectToSignUp,
28+
RedirectToTask,
2829
RedirectToUserProfile,
2930
SignedIn,
3031
SignedOut,

packages/remix/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exports[`root public exports > should not change unexpectedly 1`] = `
2121
"RedirectToOrganizationProfile",
2222
"RedirectToSignIn",
2323
"RedirectToSignUp",
24+
"RedirectToTask",
2425
"RedirectToUserProfile",
2526
"SignIn",
2627
"SignInButton",

packages/tanstack-react-start/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ exports[`root public exports > should not change unexpectedly 1`] = `
3232
"RedirectToOrganizationProfile",
3333
"RedirectToSignIn",
3434
"RedirectToSignUp",
35+
"RedirectToTask",
3536
"RedirectToUserProfile",
3637
"SignIn",
3738
"SignInButton",

packages/vue/src/components/controlComponents.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ export const RedirectToSignUp = defineComponent((props: RedirectOptions) => {
6060
return () => null;
6161
});
6262

63+
export const RedirectToTask = defineComponent((props: RedirectOptions) => {
64+
const { sessionCtx } = useClerkContext();
65+
66+
useClerkLoaded(clerk => {
67+
if (!sessionCtx.value) {
68+
void clerk.redirectToSignIn(props);
69+
return;
70+
}
71+
72+
void clerk.__internal_navigateToTaskIfAvailable();
73+
});
74+
75+
return () => null;
76+
});
77+
6378
/**
6479
* @deprecated Use [`redirectToUserProfile()`](https://clerk.com/docs/references/javascript/clerk/redirect-methods#redirect-to-user-profile) instead.
6580
*/

0 commit comments

Comments
 (0)