1
1
import type { experimental__CheckAuthorizationWithCustomPermissions } from '@clerk/types' ;
2
- import { redirect } from 'next/navigation' ;
3
2
import React from 'react' ;
4
3
5
4
import { auth } from './auth' ;
@@ -17,43 +16,21 @@ export function SignedOut(props: React.PropsWithChildren) {
17
16
}
18
17
19
18
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
+ }
31
22
> ;
32
23
33
24
/**
34
25
* @experimental The component is experimental and subject to change in future releases.
35
26
*/
36
27
export function experimental__Gate ( gateProps : GateServerComponentProps ) {
37
- const { children, fallback, redirectTo , ...restAuthorizedParams } = gateProps ;
28
+ const { children, fallback, ...restAuthorizedParams } = gateProps ;
38
29
const { experimental__has } = auth ( ) ;
39
30
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 } </ > ;
56
33
}
57
34
58
- return < > { children } </ > ;
35
+ return < > { fallback ?? null } </ > ;
59
36
}
0 commit comments