1
- import type { ActJWTClaim , GetToken , MembershipRole , SignOut } from '@clerk/types' ;
1
+ import type {
2
+ ActJWTClaim ,
3
+ experimental__CheckAuthorizationWithoutPermission ,
4
+ GetToken ,
5
+ MembershipRole ,
6
+ SignOut ,
7
+ } from '@clerk/types' ;
2
8
import { useCallback } from 'react' ;
3
9
4
10
import { useAuthContext } from '../contexts/AuthContext' ;
@@ -7,6 +13,10 @@ import { invalidStateError } from '../errors';
7
13
import type IsomorphicClerk from '../isomorphicClerk' ;
8
14
import { createGetToken , createSignOut } from './utils' ;
9
15
16
+ type experimental__CheckAuthorizationSignedOut = (
17
+ params ?: Parameters < experimental__CheckAuthorizationWithoutPermission > [ 0 ] ,
18
+ ) => false ;
19
+
10
20
type UseAuthReturn =
11
21
| {
12
22
isLoaded : false ;
@@ -17,6 +27,10 @@ type UseAuthReturn =
17
27
orgId : undefined ;
18
28
orgRole : undefined ;
19
29
orgSlug : undefined ;
30
+ /**
31
+ * @experimental The method is experimental and subject to change in future releases.
32
+ */
33
+ experimental__has : experimental__CheckAuthorizationSignedOut ;
20
34
signOut : SignOut ;
21
35
getToken : GetToken ;
22
36
}
@@ -29,6 +43,10 @@ type UseAuthReturn =
29
43
orgId : null ;
30
44
orgRole : null ;
31
45
orgSlug : null ;
46
+ /**
47
+ * @experimental The method is experimental and subject to change in future releases.
48
+ */
49
+ experimental__has : experimental__CheckAuthorizationSignedOut ;
32
50
signOut : SignOut ;
33
51
getToken : GetToken ;
34
52
}
@@ -41,6 +59,10 @@ type UseAuthReturn =
41
59
orgId : null ;
42
60
orgRole : null ;
43
61
orgSlug : null ;
62
+ /**
63
+ * @experimental The method is experimental and subject to change in future releases.
64
+ */
65
+ experimental__has : experimental__CheckAuthorizationSignedOut ;
44
66
signOut : SignOut ;
45
67
getToken : GetToken ;
46
68
}
@@ -53,6 +75,10 @@ type UseAuthReturn =
53
75
orgId : string ;
54
76
orgRole : MembershipRole ;
55
77
orgSlug : string | null ;
78
+ /**
79
+ * @experimental The method is experimental and subject to change in future releases.
80
+ */
81
+ experimental__has : experimental__CheckAuthorizationWithoutPermission ;
56
82
signOut : SignOut ;
57
83
getToken : GetToken ;
58
84
} ;
@@ -105,6 +131,24 @@ export const useAuth: UseAuth = () => {
105
131
const getToken : GetToken = useCallback ( createGetToken ( isomorphicClerk ) , [ isomorphicClerk ] ) ;
106
132
const signOut : SignOut = useCallback ( createSignOut ( isomorphicClerk ) , [ isomorphicClerk ] ) ;
107
133
134
+ const has = useCallback (
135
+ ( params ?: Parameters < experimental__CheckAuthorizationWithoutPermission > [ 0 ] ) => {
136
+ if ( ! orgId || ! userId || ! orgRole ) {
137
+ return false ;
138
+ }
139
+
140
+ if ( ! params ) {
141
+ return false ;
142
+ }
143
+
144
+ if ( params . role ) {
145
+ return orgRole === params . role ;
146
+ }
147
+ return false ;
148
+ } ,
149
+ [ orgId , orgRole , userId ] ,
150
+ ) ;
151
+
108
152
if ( sessionId === undefined && userId === undefined ) {
109
153
return {
110
154
isLoaded : false ,
@@ -115,6 +159,7 @@ export const useAuth: UseAuth = () => {
115
159
orgId : undefined ,
116
160
orgRole : undefined ,
117
161
orgSlug : undefined ,
162
+ experimental__has : ( ) => false ,
118
163
signOut,
119
164
getToken,
120
165
} ;
@@ -130,6 +175,7 @@ export const useAuth: UseAuth = () => {
130
175
orgId : null ,
131
176
orgRole : null ,
132
177
orgSlug : null ,
178
+ experimental__has : ( ) => false ,
133
179
signOut,
134
180
getToken,
135
181
} ;
@@ -145,6 +191,7 @@ export const useAuth: UseAuth = () => {
145
191
orgId,
146
192
orgRole,
147
193
orgSlug : orgSlug || null ,
194
+ experimental__has : has ,
148
195
signOut,
149
196
getToken,
150
197
} ;
@@ -160,6 +207,7 @@ export const useAuth: UseAuth = () => {
160
207
orgId : null ,
161
208
orgRole : null ,
162
209
orgSlug : null ,
210
+ experimental__has : ( ) => false ,
163
211
signOut,
164
212
getToken,
165
213
} ;
0 commit comments