@adonis-agora/authkit-react 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +72 -68
- package/build/index.js +38 -36
- package/build/src/components/can_permission.d.ts +9 -0
- package/build/src/components/can_permission.js +7 -0
- package/build/src/components/sign_in_button.d.ts +1 -1
- package/build/src/components/sign_out_button.d.ts +1 -1
- package/build/src/config.d.ts +3 -1
- package/build/src/config.js +19 -14
- package/build/src/hooks/use_can.d.ts +13 -0
- package/build/src/hooks/use_can.js +91 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,68 +1,72 @@
|
|
|
1
|
-
export { useAuth } from
|
|
2
|
-
export { AuthProvider, AuthContext } from
|
|
3
|
-
export type { AuthProviderProps } from
|
|
4
|
-
export { AuthkitProvider } from
|
|
5
|
-
export type { AuthkitProviderProps } from
|
|
6
|
-
export { AuthkitConfigContext, useAuthkitConfig, resolveConfig, buildAuthUrl, DEFAULT_CONFIG, } from
|
|
7
|
-
export type { AuthkitConfig, ResolvedAuthkitConfig, AuthkitEndpoints, AuthkitIdpMode, } from
|
|
8
|
-
export { useSignIn } from
|
|
9
|
-
export type { SignInOptions } from
|
|
10
|
-
export { useSignOut } from
|
|
11
|
-
export type { SignOutOptions } from
|
|
12
|
-
export { useUser } from
|
|
13
|
-
export type { UseUserResult } from
|
|
14
|
-
export { useProfile } from
|
|
15
|
-
export type { UseProfileResult, ProfileUpdate } from
|
|
16
|
-
export { useSessions } from
|
|
17
|
-
export type { UseSessionsResult, AuthSession } from
|
|
18
|
-
export { useAuthorizedApps } from
|
|
19
|
-
export type { UseAuthorizedAppsResult, AuthorizedApp } from
|
|
20
|
-
export { useOrganizations } from
|
|
21
|
-
export type { UseOrganizationsResult, OrgEntry } from
|
|
22
|
-
export { useOrganization } from
|
|
23
|
-
export type { UseOrganizationResult, ActiveOrgDetail, OrgMemberEntry } from
|
|
24
|
-
export { useSwitchOrganization } from
|
|
25
|
-
export type { UseSwitchOrganizationResult } from
|
|
26
|
-
export { useOrgInvitations } from
|
|
27
|
-
export type { UseOrgInvitationsResult, OrgInvitationEntry } from
|
|
28
|
-
export { jsonRequest, useResource } from
|
|
29
|
-
export type { ResourceState } from
|
|
30
|
-
export { usePasskeyAutofill } from
|
|
31
|
-
export type { UsePasskeyAutofillOptions } from
|
|
32
|
-
export { usePasswordStrength, heuristicScorer, } from
|
|
33
|
-
export type { PasswordStrengthScore, PasswordStrengthResult, PasswordScorer, UsePasswordStrengthOptions, } from
|
|
34
|
-
export { deriveInitials, currentUrl } from
|
|
35
|
-
export { Authenticated, Guest } from
|
|
36
|
-
export type { AuthenticatedProps, GuestProps } from
|
|
37
|
-
export { Can } from
|
|
38
|
-
export type { CanProps } from
|
|
39
|
-
export {
|
|
40
|
-
export type {
|
|
41
|
-
export {
|
|
42
|
-
export type {
|
|
43
|
-
export {
|
|
44
|
-
export type {
|
|
45
|
-
export {
|
|
46
|
-
export type {
|
|
47
|
-
export {
|
|
48
|
-
export type {
|
|
49
|
-
export {
|
|
50
|
-
export type {
|
|
51
|
-
export {
|
|
52
|
-
export type {
|
|
53
|
-
export {
|
|
54
|
-
export type {
|
|
55
|
-
export {
|
|
56
|
-
export type {
|
|
57
|
-
export {
|
|
58
|
-
export type {
|
|
59
|
-
export {
|
|
60
|
-
export type {
|
|
61
|
-
export {
|
|
62
|
-
export type {
|
|
63
|
-
export
|
|
64
|
-
export {
|
|
65
|
-
export
|
|
66
|
-
export {
|
|
67
|
-
export {
|
|
68
|
-
export {
|
|
1
|
+
export { useAuth } from "./src/use_auth.js";
|
|
2
|
+
export { AuthProvider, AuthContext } from "./src/provider.js";
|
|
3
|
+
export type { AuthProviderProps } from "./src/provider.js";
|
|
4
|
+
export { AuthkitProvider } from "./src/authkit_provider.js";
|
|
5
|
+
export type { AuthkitProviderProps } from "./src/authkit_provider.js";
|
|
6
|
+
export { AuthkitConfigContext, useAuthkitConfig, resolveConfig, buildAuthUrl, DEFAULT_CONFIG, } from "./src/config.js";
|
|
7
|
+
export type { AuthkitConfig, ResolvedAuthkitConfig, AuthkitEndpoints, AuthkitIdpMode, } from "./src/config.js";
|
|
8
|
+
export { useSignIn } from "./src/hooks/use_sign_in.js";
|
|
9
|
+
export type { SignInOptions } from "./src/hooks/use_sign_in.js";
|
|
10
|
+
export { useSignOut } from "./src/hooks/use_sign_out.js";
|
|
11
|
+
export type { SignOutOptions } from "./src/hooks/use_sign_out.js";
|
|
12
|
+
export { useUser } from "./src/hooks/use_user.js";
|
|
13
|
+
export type { UseUserResult } from "./src/hooks/use_user.js";
|
|
14
|
+
export { useProfile } from "./src/hooks/use_profile.js";
|
|
15
|
+
export type { UseProfileResult, ProfileUpdate, } from "./src/hooks/use_profile.js";
|
|
16
|
+
export { useSessions } from "./src/hooks/use_sessions.js";
|
|
17
|
+
export type { UseSessionsResult, AuthSession, } from "./src/hooks/use_sessions.js";
|
|
18
|
+
export { useAuthorizedApps } from "./src/hooks/use_authorized_apps.js";
|
|
19
|
+
export type { UseAuthorizedAppsResult, AuthorizedApp, } from "./src/hooks/use_authorized_apps.js";
|
|
20
|
+
export { useOrganizations } from "./src/hooks/use_organizations.js";
|
|
21
|
+
export type { UseOrganizationsResult, OrgEntry, } from "./src/hooks/use_organizations.js";
|
|
22
|
+
export { useOrganization } from "./src/hooks/use_organization.js";
|
|
23
|
+
export type { UseOrganizationResult, ActiveOrgDetail, OrgMemberEntry, } from "./src/hooks/use_organization.js";
|
|
24
|
+
export { useSwitchOrganization } from "./src/hooks/use_switch_organization.js";
|
|
25
|
+
export type { UseSwitchOrganizationResult } from "./src/hooks/use_switch_organization.js";
|
|
26
|
+
export { useOrgInvitations } from "./src/hooks/use_org_invitations.js";
|
|
27
|
+
export type { UseOrgInvitationsResult, OrgInvitationEntry, } from "./src/hooks/use_org_invitations.js";
|
|
28
|
+
export { jsonRequest, useResource } from "./src/hooks/use_resource.js";
|
|
29
|
+
export type { ResourceState } from "./src/hooks/use_resource.js";
|
|
30
|
+
export { usePasskeyAutofill } from "./src/hooks/use_passkey_autofill.js";
|
|
31
|
+
export type { UsePasskeyAutofillOptions } from "./src/hooks/use_passkey_autofill.js";
|
|
32
|
+
export { usePasswordStrength, heuristicScorer, } from "./src/hooks/use_password_strength.js";
|
|
33
|
+
export type { PasswordStrengthScore, PasswordStrengthResult, PasswordScorer, UsePasswordStrengthOptions, } from "./src/hooks/use_password_strength.js";
|
|
34
|
+
export { deriveInitials, currentUrl } from "./src/utils.js";
|
|
35
|
+
export { Authenticated, Guest } from "./src/components/authenticated.js";
|
|
36
|
+
export type { AuthenticatedProps, GuestProps, } from "./src/components/authenticated.js";
|
|
37
|
+
export { Can } from "./src/components/can.js";
|
|
38
|
+
export type { CanProps } from "./src/components/can.js";
|
|
39
|
+
export { CanPermission } from "./src/components/can_permission.js";
|
|
40
|
+
export type { CanPermissionProps } from "./src/components/can_permission.js";
|
|
41
|
+
export { useCan, checkCan, invalidateCanCache } from "./src/hooks/use_can.js";
|
|
42
|
+
export type { UseCanResult } from "./src/hooks/use_can.js";
|
|
43
|
+
export { SignInButton } from "./src/components/sign_in_button.js";
|
|
44
|
+
export type { SignInButtonProps } from "./src/components/sign_in_button.js";
|
|
45
|
+
export { SignOutButton } from "./src/components/sign_out_button.js";
|
|
46
|
+
export type { SignOutButtonProps } from "./src/components/sign_out_button.js";
|
|
47
|
+
export { Avatar } from "./src/components/avatar.js";
|
|
48
|
+
export type { AvatarProps } from "./src/components/avatar.js";
|
|
49
|
+
export { UserButton } from "./src/components/user_button.js";
|
|
50
|
+
export type { UserButtonProps } from "./src/components/user_button.js";
|
|
51
|
+
export { UserProfile } from "./src/components/user_profile.js";
|
|
52
|
+
export type { UserProfileProps } from "./src/components/user_profile.js";
|
|
53
|
+
export { AuthorizedApps } from "./src/components/authorized_apps.js";
|
|
54
|
+
export type { AuthorizedAppsProps } from "./src/components/authorized_apps.js";
|
|
55
|
+
export { PasswordStrengthMeter } from "./src/components/password_strength_meter.js";
|
|
56
|
+
export type { PasswordStrengthMeterProps } from "./src/components/password_strength_meter.js";
|
|
57
|
+
export { OrganizationSwitcher } from "./src/components/organization_switcher.js";
|
|
58
|
+
export type { OrganizationSwitcherProps } from "./src/components/organization_switcher.js";
|
|
59
|
+
export { OrganizationProfile } from "./src/components/organization_profile.js";
|
|
60
|
+
export type { OrganizationProfileProps } from "./src/components/organization_profile.js";
|
|
61
|
+
export { KeyRotation } from "./src/components/key_rotation.js";
|
|
62
|
+
export type { KeyRotationProps } from "./src/components/key_rotation.js";
|
|
63
|
+
export { hasGlobalRole, hasAnyGlobalRole, hasAllGlobalRoles, hasAppRole, hasAnyAppRole, hasAllAppRoles, } from "./src/roles.js";
|
|
64
|
+
export type { AuthUser, AuthSharedProps, AuthState } from "./src/types.js";
|
|
65
|
+
export { createAuthkitClient, AuthkitClientError, } from "./src/client/client.js";
|
|
66
|
+
export type { AuthkitClient, AuthkitClientOptions, } from "./src/client/client.js";
|
|
67
|
+
export type { AdminUser, AdminUserListResult, CreateUserInput, UpdateUserInput, UserSessionsResult, RevokeSessionsResult, AdminSessionEntry, AdminGrantEntry, AdminClient, AdminClientListResult, CreatedClientResult, RegenerateSecretResult, CreateClientInput, UpdateClientInput, RoleCatalogEntry, RoleListResult, CreateRoleInput, UpdateRoleInput, AdminOrgEntry, AdminOrgMember, AdminOrgInvitation, AdminOrgDetail, AdminOrgListResult, CreateOrgInput, UpdateOrgInput, AuditEventEntry, AuditListResult, AuditListParams, SettingEntry, SettingListResult, ImpersonationPanel, DailyPoint, AdminOverview, AccountCapabilities, AccountMe, AccountSecurityOverview, AccountSessionEntry, AccountSessionsResult, RevokeSessionResult, RevokeOthersResult, RevokeAllResult, AccountAppEntry, AccountAppsResult, RevokeAppResult, PasskeySummaryEntry, AccountMfaStatus, AccountPasskeysResult, RemovePasskeyResult, PatEntry, CreatedPatResult, AccountTokensResult, CreateTokenInput, RevokeTokenResult, UpdateProfileInput, UpdateProfileResult, ChangePasswordInput, RequestEmailChangeInput, OkResult, EmailChangeResult, AccountOrgEntry, AccountOrgsResult, AccountOrgDetail, AccountOrgInvitationsResult, ApiErrorBody, KeysStatus, ManagedKeyInfo, KeysRotateInput, KeysRotateResult, } from "./src/client/types.js";
|
|
68
|
+
export { AuthkitClientProvider, useAuthkitClient, createAuthkitQueryClient, } from "./src/client/context.js";
|
|
69
|
+
export type { AuthkitClientProviderProps } from "./src/client/context.js";
|
|
70
|
+
export { authkitKeys } from "./src/queries/keys.js";
|
|
71
|
+
export { useOverviewQueryOptions, useUsersQueryOptions, useUserQueryOptions, useUserSessionsQueryOptions, useCreateUserMutationOptions, useUpdateUserMutationOptions, useDisableUserMutationOptions, useEnableUserMutationOptions, useResetPasswordMutationOptions, useDeleteUserMutationOptions, useRevokeUserSessionsMutationOptions, useSessionsQueryOptions, useRevokeAllSessionsMutationOptions, useClientsQueryOptions, useClientQueryOptions, useCreateClientMutationOptions, useUpdateClientMutationOptions, useDeleteClientMutationOptions, useRegenerateClientSecretMutationOptions, useRolesQueryOptions, useCreateRoleMutationOptions, useUpdateRoleMutationOptions, useDeleteRoleMutationOptions, useOrgsQueryOptions, useOrgQueryOptions, useCreateOrgMutationOptions, useUpdateOrgMutationOptions, useDeleteOrgMutationOptions, useAddOrgMemberMutationOptions, useRemoveOrgMemberMutationOptions, useUpdateOrgMemberRoleMutationOptions, useCreateOrgInvitationMutationOptions, useRevokeOrgInvitationMutationOptions, useAuditQueryOptions, useSettingsQueryOptions, useSetSettingMutationOptions, useRemoveSettingMutationOptions, useImpersonationQueryOptions, useKeysQueryOptions, useRotateKeysMutationOptions, } from "./src/queries/admin/index.js";
|
|
72
|
+
export { useMeQueryOptions, useSecurityQueryOptions, useUpdateProfileMutationOptions, useChangePasswordMutationOptions, useEmailChangeMutationOptions, useCancelEmailChangeMutationOptions, useAccountSessionsQueryOptions, useRevokeSessionMutationOptions, useRevokeOtherSessionsMutationOptions, useAccountRevokeAllSessionsMutationOptions, useAppsQueryOptions, useRevokeAppMutationOptions, useMfaQueryOptions, usePasskeysQueryOptions, useRemovePasskeyMutationOptions, useTokensQueryOptions, useCreateTokenMutationOptions, useRevokeTokenMutationOptions, useAccountOrgsQueryOptions, useAccountOrgQueryOptions, useAccountOrgInvitationsQueryOptions, } from "./src/queries/account/index.js";
|
package/build/index.js
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
export { useAuth } from
|
|
2
|
-
export { AuthProvider, AuthContext } from
|
|
3
|
-
export { AuthkitProvider } from
|
|
4
|
-
export { AuthkitConfigContext, useAuthkitConfig, resolveConfig, buildAuthUrl, DEFAULT_CONFIG, } from
|
|
5
|
-
export { useSignIn } from
|
|
6
|
-
export { useSignOut } from
|
|
7
|
-
export { useUser } from
|
|
8
|
-
export { useProfile } from
|
|
9
|
-
export { useSessions } from
|
|
10
|
-
export { useAuthorizedApps } from
|
|
11
|
-
export { useOrganizations } from
|
|
12
|
-
export { useOrganization } from
|
|
13
|
-
export { useSwitchOrganization } from
|
|
14
|
-
export { useOrgInvitations } from
|
|
15
|
-
export { jsonRequest, useResource } from
|
|
16
|
-
export { usePasskeyAutofill } from
|
|
17
|
-
export { usePasswordStrength, heuristicScorer, } from
|
|
18
|
-
export { deriveInitials, currentUrl } from
|
|
19
|
-
export { Authenticated, Guest } from
|
|
20
|
-
export { Can } from
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
1
|
+
export { useAuth } from "./src/use_auth.js";
|
|
2
|
+
export { AuthProvider, AuthContext } from "./src/provider.js";
|
|
3
|
+
export { AuthkitProvider } from "./src/authkit_provider.js";
|
|
4
|
+
export { AuthkitConfigContext, useAuthkitConfig, resolveConfig, buildAuthUrl, DEFAULT_CONFIG, } from "./src/config.js";
|
|
5
|
+
export { useSignIn } from "./src/hooks/use_sign_in.js";
|
|
6
|
+
export { useSignOut } from "./src/hooks/use_sign_out.js";
|
|
7
|
+
export { useUser } from "./src/hooks/use_user.js";
|
|
8
|
+
export { useProfile } from "./src/hooks/use_profile.js";
|
|
9
|
+
export { useSessions } from "./src/hooks/use_sessions.js";
|
|
10
|
+
export { useAuthorizedApps } from "./src/hooks/use_authorized_apps.js";
|
|
11
|
+
export { useOrganizations } from "./src/hooks/use_organizations.js";
|
|
12
|
+
export { useOrganization } from "./src/hooks/use_organization.js";
|
|
13
|
+
export { useSwitchOrganization } from "./src/hooks/use_switch_organization.js";
|
|
14
|
+
export { useOrgInvitations } from "./src/hooks/use_org_invitations.js";
|
|
15
|
+
export { jsonRequest, useResource } from "./src/hooks/use_resource.js";
|
|
16
|
+
export { usePasskeyAutofill } from "./src/hooks/use_passkey_autofill.js";
|
|
17
|
+
export { usePasswordStrength, heuristicScorer, } from "./src/hooks/use_password_strength.js";
|
|
18
|
+
export { deriveInitials, currentUrl } from "./src/utils.js";
|
|
19
|
+
export { Authenticated, Guest } from "./src/components/authenticated.js";
|
|
20
|
+
export { Can } from "./src/components/can.js";
|
|
21
|
+
export { CanPermission } from "./src/components/can_permission.js";
|
|
22
|
+
export { useCan, checkCan, invalidateCanCache } from "./src/hooks/use_can.js";
|
|
23
|
+
export { SignInButton } from "./src/components/sign_in_button.js";
|
|
24
|
+
export { SignOutButton } from "./src/components/sign_out_button.js";
|
|
25
|
+
export { Avatar } from "./src/components/avatar.js";
|
|
26
|
+
export { UserButton } from "./src/components/user_button.js";
|
|
27
|
+
export { UserProfile } from "./src/components/user_profile.js";
|
|
28
|
+
export { AuthorizedApps } from "./src/components/authorized_apps.js";
|
|
29
|
+
export { PasswordStrengthMeter } from "./src/components/password_strength_meter.js";
|
|
30
|
+
export { OrganizationSwitcher } from "./src/components/organization_switcher.js";
|
|
31
|
+
export { OrganizationProfile } from "./src/components/organization_profile.js";
|
|
32
|
+
export { KeyRotation } from "./src/components/key_rotation.js";
|
|
33
|
+
export { hasGlobalRole, hasAnyGlobalRole, hasAllGlobalRoles, hasAppRole, hasAnyAppRole, hasAllAppRoles, } from "./src/roles.js";
|
|
34
|
+
export { createAuthkitClient, AuthkitClientError, } from "./src/client/client.js";
|
|
35
|
+
export { AuthkitClientProvider, useAuthkitClient, createAuthkitQueryClient, } from "./src/client/context.js";
|
|
36
|
+
export { authkitKeys } from "./src/queries/keys.js";
|
|
37
|
+
export { useOverviewQueryOptions, useUsersQueryOptions, useUserQueryOptions, useUserSessionsQueryOptions, useCreateUserMutationOptions, useUpdateUserMutationOptions, useDisableUserMutationOptions, useEnableUserMutationOptions, useResetPasswordMutationOptions, useDeleteUserMutationOptions, useRevokeUserSessionsMutationOptions, useSessionsQueryOptions, useRevokeAllSessionsMutationOptions, useClientsQueryOptions, useClientQueryOptions, useCreateClientMutationOptions, useUpdateClientMutationOptions, useDeleteClientMutationOptions, useRegenerateClientSecretMutationOptions, useRolesQueryOptions, useCreateRoleMutationOptions, useUpdateRoleMutationOptions, useDeleteRoleMutationOptions, useOrgsQueryOptions, useOrgQueryOptions, useCreateOrgMutationOptions, useUpdateOrgMutationOptions, useDeleteOrgMutationOptions, useAddOrgMemberMutationOptions, useRemoveOrgMemberMutationOptions, useUpdateOrgMemberRoleMutationOptions, useCreateOrgInvitationMutationOptions, useRevokeOrgInvitationMutationOptions, useAuditQueryOptions, useSettingsQueryOptions, useSetSettingMutationOptions, useRemoveSettingMutationOptions, useImpersonationQueryOptions, useKeysQueryOptions, useRotateKeysMutationOptions, } from "./src/queries/admin/index.js";
|
|
38
|
+
export { useMeQueryOptions, useSecurityQueryOptions, useUpdateProfileMutationOptions, useChangePasswordMutationOptions, useEmailChangeMutationOptions, useCancelEmailChangeMutationOptions, useAccountSessionsQueryOptions, useRevokeSessionMutationOptions, useRevokeOtherSessionsMutationOptions, useAccountRevokeAllSessionsMutationOptions, useAppsQueryOptions, useRevokeAppMutationOptions, useMfaQueryOptions, usePasskeysQueryOptions, useRemovePasskeyMutationOptions, useTokensQueryOptions, useCreateTokenMutationOptions, useRevokeTokenMutationOptions, useAccountOrgsQueryOptions, useAccountOrgQueryOptions, useAccountOrgInvitationsQueryOptions, } from "./src/queries/account/index.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface CanPermissionProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
permission: string;
|
|
5
|
+
resource?: string;
|
|
6
|
+
loadingFallback?: ReactNode;
|
|
7
|
+
fallback?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function CanPermission({ children, permission, resource, loadingFallback, fallback, }: CanPermissionProps): import("react").FunctionComponentElement<import("react").FragmentProps>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
|
+
import { useCan } from "../hooks/use_can.js";
|
|
3
|
+
export function CanPermission({ children, permission, resource, loadingFallback = null, fallback = null, }) {
|
|
4
|
+
const { allowed, loading } = useCan(permission, resource);
|
|
5
|
+
const out = loading ? loadingFallback : allowed ? children : fallback;
|
|
6
|
+
return createElement(Fragment, null, out);
|
|
7
|
+
}
|
|
@@ -13,6 +13,7 @@ export declare function SignInButton({ children, returnTo, showWhenAuthenticated
|
|
|
13
13
|
style?: import("react").CSSProperties | undefined;
|
|
14
14
|
title?: string | undefined | undefined;
|
|
15
15
|
role?: import("react").AriaRole | undefined;
|
|
16
|
+
resource?: string | undefined | undefined;
|
|
16
17
|
disabled?: boolean | undefined | undefined;
|
|
17
18
|
formAction?: string | ((formData: FormData) => void | Promise<void>) | undefined;
|
|
18
19
|
formEncType?: string | undefined | undefined;
|
|
@@ -46,7 +47,6 @@ export declare function SignInButton({ children, returnTo, showWhenAuthenticated
|
|
|
46
47
|
prefix?: string | undefined | undefined;
|
|
47
48
|
property?: string | undefined | undefined;
|
|
48
49
|
rel?: string | undefined | undefined;
|
|
49
|
-
resource?: string | undefined | undefined;
|
|
50
50
|
rev?: string | undefined | undefined;
|
|
51
51
|
typeof?: string | undefined | undefined;
|
|
52
52
|
vocab?: string | undefined | undefined;
|
|
@@ -12,6 +12,7 @@ export declare function SignOutButton({ children, returnTo, className, ...rest }
|
|
|
12
12
|
style?: import("react").CSSProperties | undefined;
|
|
13
13
|
title?: string | undefined | undefined;
|
|
14
14
|
role?: import("react").AriaRole | undefined;
|
|
15
|
+
resource?: string | undefined | undefined;
|
|
15
16
|
disabled?: boolean | undefined | undefined;
|
|
16
17
|
formAction?: string | ((formData: FormData) => void | Promise<void>) | undefined;
|
|
17
18
|
formEncType?: string | undefined | undefined;
|
|
@@ -45,7 +46,6 @@ export declare function SignOutButton({ children, returnTo, className, ...rest }
|
|
|
45
46
|
prefix?: string | undefined | undefined;
|
|
46
47
|
property?: string | undefined | undefined;
|
|
47
48
|
rel?: string | undefined | undefined;
|
|
48
|
-
resource?: string | undefined | undefined;
|
|
49
49
|
rev?: string | undefined | undefined;
|
|
50
50
|
typeof?: string | undefined | undefined;
|
|
51
51
|
vocab?: string | undefined | undefined;
|
package/build/src/config.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ export interface AuthkitEndpoints {
|
|
|
5
5
|
passkeys: string;
|
|
6
6
|
orgs: string;
|
|
7
7
|
orgInvitations: string;
|
|
8
|
+
can: string;
|
|
8
9
|
}
|
|
9
|
-
export type AuthkitIdpMode =
|
|
10
|
+
export type AuthkitIdpMode = "authkit" | "external";
|
|
10
11
|
export interface AuthkitConfig {
|
|
11
12
|
loginUrl?: string;
|
|
12
13
|
logoutUrl?: string;
|
|
@@ -14,6 +15,7 @@ export interface AuthkitConfig {
|
|
|
14
15
|
endpoints?: Partial<AuthkitEndpoints>;
|
|
15
16
|
csrfToken?: string;
|
|
16
17
|
idp?: AuthkitIdpMode;
|
|
18
|
+
canPath?: string;
|
|
17
19
|
}
|
|
18
20
|
export interface ResolvedAuthkitConfig {
|
|
19
21
|
loginUrl: string;
|
package/build/src/config.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { createContext, useContext } from
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
2
|
export const DEFAULT_CONFIG = {
|
|
3
|
-
idp:
|
|
4
|
-
loginUrl:
|
|
5
|
-
logoutUrl:
|
|
6
|
-
profileUrl:
|
|
3
|
+
idp: "authkit",
|
|
4
|
+
loginUrl: "/auth/login",
|
|
5
|
+
logoutUrl: "/account/logout",
|
|
6
|
+
profileUrl: "/account/security",
|
|
7
7
|
endpoints: {
|
|
8
|
-
profile:
|
|
9
|
-
sessions:
|
|
10
|
-
apps:
|
|
11
|
-
passkeys:
|
|
12
|
-
orgs:
|
|
13
|
-
orgInvitations:
|
|
8
|
+
profile: "/account/security/profile",
|
|
9
|
+
sessions: "/account/security",
|
|
10
|
+
apps: "/account/apps",
|
|
11
|
+
passkeys: "/account/mfa/passkeys",
|
|
12
|
+
orgs: "/account/orgs/json",
|
|
13
|
+
orgInvitations: "/account/orgs/invitations/json",
|
|
14
|
+
can: "/authz/can",
|
|
14
15
|
},
|
|
15
16
|
};
|
|
16
17
|
export function resolveConfig(config) {
|
|
@@ -24,16 +25,20 @@ export function resolveConfig(config) {
|
|
|
24
25
|
apps: config?.endpoints?.apps ?? DEFAULT_CONFIG.endpoints.apps,
|
|
25
26
|
passkeys: config?.endpoints?.passkeys ?? DEFAULT_CONFIG.endpoints.passkeys,
|
|
26
27
|
orgs: config?.endpoints?.orgs ?? DEFAULT_CONFIG.endpoints.orgs,
|
|
27
|
-
orgInvitations: config?.endpoints?.orgInvitations ??
|
|
28
|
+
orgInvitations: config?.endpoints?.orgInvitations ??
|
|
29
|
+
DEFAULT_CONFIG.endpoints.orgInvitations,
|
|
30
|
+
can: config?.endpoints?.can ??
|
|
31
|
+
config?.canPath ??
|
|
32
|
+
DEFAULT_CONFIG.endpoints.can,
|
|
28
33
|
},
|
|
29
34
|
csrfToken: config?.csrfToken,
|
|
30
|
-
idp: config?.idp ??
|
|
35
|
+
idp: config?.idp ?? "authkit",
|
|
31
36
|
};
|
|
32
37
|
}
|
|
33
38
|
export function buildAuthUrl(base, returnTo) {
|
|
34
39
|
if (!returnTo)
|
|
35
40
|
return base;
|
|
36
|
-
const sep = base.includes(
|
|
41
|
+
const sep = base.includes("?") ? "&" : "?";
|
|
37
42
|
return `${base}${sep}returnTo=${encodeURIComponent(returnTo)}`;
|
|
38
43
|
}
|
|
39
44
|
export const AuthkitConfigContext = createContext(DEFAULT_CONFIG);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface UseCanResult {
|
|
2
|
+
allowed: boolean;
|
|
3
|
+
loading: boolean;
|
|
4
|
+
error?: Error;
|
|
5
|
+
}
|
|
6
|
+
export declare const canCache: {
|
|
7
|
+
resolved: Map<string, boolean>;
|
|
8
|
+
inflight: Map<string, Promise<boolean>>;
|
|
9
|
+
clear(): void;
|
|
10
|
+
};
|
|
11
|
+
export declare function invalidateCanCache(): void;
|
|
12
|
+
export declare function checkCan(path: string, permission: string, resource?: string, csrfToken?: string, principal?: string): Promise<boolean>;
|
|
13
|
+
export declare function useCan(permission: string, resource?: string): UseCanResult;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useContext, useEffect, useState } from "react";
|
|
2
|
+
import { usePage } from "@inertiajs/react";
|
|
3
|
+
import { useAuthkitConfig } from "../config.js";
|
|
4
|
+
import { AuthContext } from "../provider.js";
|
|
5
|
+
import { jsonRequest } from "./use_resource.js";
|
|
6
|
+
const ANON_PRINCIPAL = "anon";
|
|
7
|
+
function usePrincipalId() {
|
|
8
|
+
const fromContext = useContext(AuthContext);
|
|
9
|
+
let fromPage;
|
|
10
|
+
try {
|
|
11
|
+
fromPage = usePage().props?.authkit;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
fromPage = undefined;
|
|
15
|
+
}
|
|
16
|
+
return (fromContext ?? fromPage)?.user?.id ?? ANON_PRINCIPAL;
|
|
17
|
+
}
|
|
18
|
+
function cacheKey(path, principal, permission, resource) {
|
|
19
|
+
return [principal, path, permission, resource ?? ""].join("|");
|
|
20
|
+
}
|
|
21
|
+
export const canCache = {
|
|
22
|
+
resolved: new Map(),
|
|
23
|
+
inflight: new Map(),
|
|
24
|
+
clear() {
|
|
25
|
+
this.resolved.clear();
|
|
26
|
+
this.inflight.clear();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export function invalidateCanCache() {
|
|
30
|
+
canCache.clear();
|
|
31
|
+
}
|
|
32
|
+
export async function checkCan(path, permission, resource, csrfToken, principal = ANON_PRINCIPAL) {
|
|
33
|
+
const key = cacheKey(path, principal, permission, resource);
|
|
34
|
+
const cached = canCache.resolved.get(key);
|
|
35
|
+
if (cached !== undefined)
|
|
36
|
+
return cached;
|
|
37
|
+
const pending = canCache.inflight.get(key);
|
|
38
|
+
if (pending)
|
|
39
|
+
return pending;
|
|
40
|
+
const promise = jsonRequest(path, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
csrfToken,
|
|
43
|
+
body: JSON.stringify({ permission, ...(resource ? { resource } : {}) }),
|
|
44
|
+
})
|
|
45
|
+
.then((res) => {
|
|
46
|
+
const allowed = res?.allowed === true;
|
|
47
|
+
canCache.resolved.set(key, allowed);
|
|
48
|
+
return allowed;
|
|
49
|
+
})
|
|
50
|
+
.finally(() => {
|
|
51
|
+
canCache.inflight.delete(key);
|
|
52
|
+
});
|
|
53
|
+
canCache.inflight.set(key, promise);
|
|
54
|
+
return promise;
|
|
55
|
+
}
|
|
56
|
+
export function useCan(permission, resource) {
|
|
57
|
+
const config = useAuthkitConfig();
|
|
58
|
+
const principal = usePrincipalId();
|
|
59
|
+
const path = config.endpoints.can;
|
|
60
|
+
const key = cacheKey(path, principal, permission, resource);
|
|
61
|
+
const [state, setState] = useState(() => {
|
|
62
|
+
const cached = canCache.resolved.get(key);
|
|
63
|
+
return cached !== undefined
|
|
64
|
+
? { allowed: cached, loading: false }
|
|
65
|
+
: { allowed: false, loading: true };
|
|
66
|
+
});
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
let cancelled = false;
|
|
69
|
+
const hit = canCache.resolved.get(key);
|
|
70
|
+
if (hit !== undefined) {
|
|
71
|
+
setState((s) => !s.loading && s.allowed === hit && s.error === undefined
|
|
72
|
+
? s
|
|
73
|
+
: { allowed: hit, loading: false });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
setState((s) => (s.loading ? s : { ...s, loading: true }));
|
|
77
|
+
checkCan(path, permission, resource, config.csrfToken, principal)
|
|
78
|
+
.then((allowed) => {
|
|
79
|
+
if (!cancelled)
|
|
80
|
+
setState({ allowed, loading: false });
|
|
81
|
+
})
|
|
82
|
+
.catch((err) => {
|
|
83
|
+
if (!cancelled)
|
|
84
|
+
setState({ allowed: false, loading: false, error: err });
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
cancelled = true;
|
|
88
|
+
};
|
|
89
|
+
}, [key, path, permission, resource, config.csrfToken, principal]);
|
|
90
|
+
return state;
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Frontend ergonomics over AuthKit for AdonisJS + Inertia + React apps: a typed useAuth() hook, role-gating hooks and gating components.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|