Skip to content

Commit 91c3ba3

Browse files
committed
chore(nextjs): Drop redirect from RSC <Gate/>
1 parent c330e9e commit 91c3ba3

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed
Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { experimental__CheckAuthorizationWithCustomPermissions } from '@clerk/types';
2-
import { redirect } from 'next/navigation';
32
import React from 'react';
43

54
import { auth } from './auth';
@@ -17,43 +16,21 @@ export function SignedOut(props: React.PropsWithChildren) {
1716
}
1817

1918
type GateServerComponentProps = React.PropsWithChildren<
20-
Parameters<experimental__CheckAuthorizationWithCustomPermissions>[0] &
21-
(
22-
| {
23-
fallback: React.ReactNode;
24-
redirectTo?: never;
25-
}
26-
| {
27-
fallback?: never;
28-
redirectTo: string;
29-
}
30-
)
19+
Parameters<experimental__CheckAuthorizationWithCustomPermissions>[0] & {
20+
fallback?: React.ReactNode;
21+
}
3122
>;
3223

3324
/**
3425
* @experimental The component is experimental and subject to change in future releases.
3526
*/
3627
export function experimental__Gate(gateProps: GateServerComponentProps) {
37-
const { children, fallback, redirectTo, ...restAuthorizedParams } = gateProps;
28+
const { children, fallback, ...restAuthorizedParams } = gateProps;
3829
const { experimental__has } = auth();
3930

40-
const isAuthorizedUser = experimental__has(restAuthorizedParams);
41-
42-
if (!redirectTo && !fallback) {
43-
throw new Error('Provide `<Gate />` with a `fallback` or `redirectTo`');
44-
}
45-
46-
const handleFallback = () => {
47-
if (redirectTo) {
48-
return redirect(redirectTo);
49-
}
50-
51-
return <>{fallback}</>;
52-
};
53-
54-
if (!isAuthorizedUser) {
55-
return handleFallback();
31+
if (experimental__has(restAuthorizedParams)) {
32+
return <>{children}</>;
5633
}
5734

58-
return <>{children}</>;
35+
return <>{fallback ?? null}</>;
5936
}

0 commit comments

Comments
 (0)