File tree 5 files changed +34
-8
lines changed
nextjs/src/app-router/server 5 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -210,7 +210,9 @@ const createHasAuthorization =
210
210
} ) : CheckAuthorizationWithCustomPermissions =>
211
211
params => {
212
212
if ( ! params ?. permission && ! params ?. role ) {
213
- throw new Error ( 'Missing params. `has` from `useAuth` requires a permission or role key to be passed.' ) ;
213
+ throw new Error (
214
+ 'Missing parameters. `has` from `auth` or `getAuth` requires a permission or role key to be passed.' ,
215
+ ) ;
214
216
}
215
217
216
218
if ( ! orgId || ! userId || ! orgRole || ! orgPermissions ) {
Original file line number Diff line number Diff line change @@ -17,15 +17,27 @@ export function SignedOut(props: React.PropsWithChildren) {
17
17
18
18
type ProtectServerComponentProps = React . ComponentProps < typeof ProtectClientComponent > ;
19
19
20
+ /**
21
+ * Use `<Protect/>` in order to prevent unauthenticated or unauthorized user from accessing the children passed to the component.
22
+ *
23
+ * Examples:
24
+ * ```
25
+ * <Protect permission="a_permission_key" />
26
+ * <Protect role="a_role_key" />
27
+ * <Protect condition={(has) => has({permission:"a_permission_key"})} />
28
+ * <Protect condition={(has) => has({role:"a_role_key"}) } />
29
+ * <Protect fallback={<p>Unauthorized</p>}/>
30
+ * ```
31
+ */
20
32
export function Protect ( props : ProtectServerComponentProps ) {
21
33
const { children, fallback, ...restAuthorizedParams } = props ;
22
- const { has, userId, sessionId } = auth ( ) ;
34
+ const { has, userId } = auth ( ) ;
23
35
24
36
/**
25
37
* If neither of the authorization params are passed behave as the `<SignedIn/>`
26
38
*/
27
39
if ( ! restAuthorizedParams . condition && ! restAuthorizedParams . role && ! restAuthorizedParams . permission ) {
28
- if ( userId && sessionId ) {
40
+ if ( userId ) {
29
41
return < > { children } </ > ;
30
42
}
31
43
return < > { fallback ?? null } </ > ;
Original file line number Diff line number Diff line change @@ -73,14 +73,26 @@ type ProtectProps = React.PropsWithChildren<
73
73
}
74
74
> ;
75
75
76
+ /**
77
+ * Use `<Protect/>` in order to prevent unauthenticated or unauthorized user from accessing the children passed to the component.
78
+ *
79
+ * Examples:
80
+ * ```
81
+ * <Protect permission="a_permission_key" />
82
+ * <Protect role="a_role_key" />
83
+ * <Protect condition={(has) => has({permission:"a_permission_key"})} />
84
+ * <Protect condition={(has) => has({role:"a_role_key"}) } />
85
+ * <Protect fallback={<p>Unauthorized</p>}/>
86
+ * ```
87
+ */
76
88
export const Protect = ( { children, fallback, ...restAuthorizedParams } : ProtectProps ) => {
77
- const { has, userId, sessionId } = useAuth ( ) ;
89
+ const { has, userId } = useAuth ( ) ;
78
90
79
91
/**
80
92
* If neither of the authorization params are passed behave as the `<SignedIn/>`
81
93
*/
82
94
if ( ! restAuthorizedParams . condition && ! restAuthorizedParams . role && ! restAuthorizedParams . permission ) {
83
- if ( userId && sessionId ) {
95
+ if ( userId ) {
84
96
return < > { children } </ > ;
85
97
}
86
98
return < > { fallback ?? null } </ > ;
Original file line number Diff line number Diff line change @@ -45,4 +45,4 @@ export const customLinkWrongProps = (componentName: string) =>
45
45
`Missing props. <${ componentName } .Link /> component requires the following props: url, label and labelIcon.` ;
46
46
47
47
export const useAuthHasRequiresRoleOrPermission =
48
- 'Missing params . `has` from `useAuth` requires a permission or role key to be passed.' ;
48
+ 'Missing parameters . `has` from `useAuth` requires a permission or role key to be passed.' ;
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export type OrganizationCustomRoleKey = string;
41
41
42
42
/**
43
43
* @deprecated This type is deprecated and will be removed in the next major release.
44
- * Use `OrganizationCustomRole ` instead.
44
+ * Use `OrganizationCustomRoleKey ` instead.
45
45
* MembershipRole includes `admin`, `basic_member`, `guest_member`. With the introduction of "Custom roles"
46
46
* these types will no longer match a developer's custom logic.
47
47
*/
@@ -58,7 +58,7 @@ export type OrganizationSystemPermissionKey =
58
58
| 'org:sys_domains:read' ;
59
59
60
60
/**
61
- * OrganizationPermission is a combination of system and custom permissions.
61
+ * OrganizationPermissionKey is a combination of system and custom permissions.
62
62
* System permissions are only accessible from FAPI and client-side operations/utils
63
63
*/
64
64
export type OrganizationPermissionKey = Autocomplete < OrganizationSystemPermissionKey > ;
You can’t perform that action at this time.
0 commit comments