|
1 | | -import { resolveAuthState } from '@clerk/shared/authorization'; |
2 | | -import type { |
3 | | - CheckAuthorizationWithCustomPermissions, |
4 | | - Clerk, |
5 | | - GetToken, |
6 | | - PendingSessionOptions, |
7 | | - SignOut, |
8 | | - UseAuthReturn, |
9 | | -} from '@clerk/types'; |
| 1 | +import { createCheckAuthorization, resolveAuthState } from '@clerk/shared/authorization'; |
| 2 | +import type { Clerk, GetToken, JwtPayload, PendingSessionOptions, SignOut, UseAuthReturn } from '@clerk/types'; |
10 | 3 | import { computed, type ShallowRef, watch } from 'vue'; |
11 | 4 |
|
12 | 5 | import { errorThrower } from '../errors/errorThrower'; |
13 | | -import { invalidStateError, useAuthHasRequiresRoleOrPermission } from '../errors/messages'; |
| 6 | +import { invalidStateError } from '../errors/messages'; |
14 | 7 | import type { ToComputedRefs } from '../utils'; |
15 | 8 | import { toComputedRefs } from '../utils'; |
16 | 9 | import { useClerkContext } from './useClerkContext'; |
@@ -87,26 +80,17 @@ export const useAuth: UseAuth = (options = {}) => { |
87 | 80 | const signOut: SignOut = createSignOut(clerk); |
88 | 81 |
|
89 | 82 | const result = computed<UseAuthReturn>(() => { |
90 | | - const { userId, orgId, orgRole, orgPermissions } = authCtx.value; |
91 | | - |
92 | | - const has = (params: Parameters<CheckAuthorizationWithCustomPermissions>[0]) => { |
93 | | - if (!params?.permission && !params?.role) { |
94 | | - return errorThrower.throw(useAuthHasRequiresRoleOrPermission); |
95 | | - } |
96 | | - if (!orgId || !userId || !orgRole || !orgPermissions) { |
97 | | - return false; |
98 | | - } |
99 | | - |
100 | | - if (params.permission) { |
101 | | - return orgPermissions.includes(params.permission); |
102 | | - } |
103 | | - |
104 | | - if (params.role) { |
105 | | - return orgRole === params.role; |
106 | | - } |
107 | | - |
108 | | - return false; |
109 | | - }; |
| 83 | + const { userId, orgId, orgRole, orgPermissions, sessionClaims, factorVerificationAge } = authCtx.value; |
| 84 | + |
| 85 | + const has = createCheckAuthorization({ |
| 86 | + userId, |
| 87 | + orgId, |
| 88 | + orgRole, |
| 89 | + orgPermissions, |
| 90 | + factorVerificationAge, |
| 91 | + features: ((sessionClaims as JwtPayload | undefined)?.fea as string) || '', |
| 92 | + plans: ((sessionClaims as JwtPayload | undefined)?.pla as string) || '', |
| 93 | + }); |
110 | 94 |
|
111 | 95 | const payload = resolveAuthState({ |
112 | 96 | authObject: { |
|
0 commit comments