@adonis-agora/authkit-react 0.26.0 → 1.0.0-rc.1
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/CHANGELOG.md +699 -0
- package/README.md +29 -19
- package/build/index.d.ts +3 -18
- package/build/index.js +2 -9
- package/build/src/client/client.d.ts +12 -21
- package/build/src/client/client.js +7 -15
- package/build/src/client/types.d.ts +54 -17
- package/build/src/components/authorized_apps.js +17 -13
- package/build/src/components/organization_profile.js +31 -39
- package/build/src/components/organization_switcher.js +25 -9
- package/build/src/components/user_profile.js +13 -7
- package/build/src/config.d.ts +0 -6
- package/build/src/config.js +0 -12
- package/build/src/hooks/use_resource.d.ts +0 -8
- package/build/src/hooks/use_resource.js +0 -22
- package/build/src/queries/account/index.d.ts +11 -1
- package/build/src/queries/account/index.js +14 -0
- package/build/src/queries/admin/index.d.ts +6 -21
- package/build/src/queries/keys.d.ts +1 -0
- package/build/src/queries/keys.js +1 -0
- package/package.json +12 -11
- package/skills/authkit-react-auth/SKILL.md +39 -22
- package/build/src/hooks/use_authorized_apps.d.ts +0 -16
- package/build/src/hooks/use_authorized_apps.js +0 -15
- package/build/src/hooks/use_org_invitations.d.ts +0 -19
- package/build/src/hooks/use_org_invitations.js +0 -20
- package/build/src/hooks/use_organization.d.ts +0 -23
- package/build/src/hooks/use_organization.js +0 -10
- package/build/src/hooks/use_organizations.d.ts +0 -18
- package/build/src/hooks/use_organizations.js +0 -14
- package/build/src/hooks/use_profile.d.ts +0 -13
- package/build/src/hooks/use_profile.js +0 -32
- package/build/src/hooks/use_sessions.d.ts +0 -16
- package/build/src/hooks/use_sessions.js +0 -15
- package/build/src/hooks/use_switch_organization.d.ts +0 -7
- package/build/src/hooks/use_switch_organization.js +0 -42
package/README.md
CHANGED
|
@@ -17,8 +17,8 @@ pnpm add @adonis-agora/authkit-react
|
|
|
17
17
|
|
|
18
18
|
## 1. No host AdonisJS: compartilhar a prop `authkit`
|
|
19
19
|
|
|
20
|
-
A shared-prop tem o formato `AuthSharedProps`. Use `
|
|
21
|
-
`
|
|
20
|
+
A shared-prop tem o formato `AuthSharedProps`. Use `authkit.getUser()` /
|
|
21
|
+
`authkit.identity` do `@adonis-agora/authkit-client` para preenchê-la — tipicamente
|
|
22
22
|
num middleware ou no `config/inertia.ts` (`sharedData`):
|
|
23
23
|
|
|
24
24
|
```ts
|
|
@@ -28,11 +28,11 @@ import { defineConfig } from '@adonisjs/inertia'
|
|
|
28
28
|
export default defineConfig({
|
|
29
29
|
sharedData: {
|
|
30
30
|
authkit: async (ctx) => {
|
|
31
|
-
const
|
|
32
|
-
const user = await
|
|
31
|
+
const authkit = ctx.authkit // sua instância do Authenticator
|
|
32
|
+
const user = await authkit.getUser() // mesmo shape de identityToUser/resolveUser
|
|
33
33
|
return {
|
|
34
34
|
user: user ?? null,
|
|
35
|
-
globalRoles:
|
|
35
|
+
globalRoles: authkit.identity?.globalRoles ?? [],
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
},
|
|
@@ -98,29 +98,39 @@ import { AuthProvider } from '@adonis-agora/authkit-react'
|
|
|
98
98
|
|
|
99
99
|
## 5. Config + componentes prontos
|
|
100
100
|
|
|
101
|
-
Envolva a app com `<AuthkitProvider>`
|
|
102
|
-
|
|
101
|
+
Envolva a app com `<AuthkitProvider>` (URLs, CSRF, modo de IdP). Os componentes de
|
|
102
|
+
conta (`UserProfile`, `AuthorizedApps`, `OrganizationSwitcher`, `OrganizationProfile`)
|
|
103
|
+
buscam dados pela Account API, então também precisam de `QueryClientProvider` +
|
|
104
|
+
`AuthkitClientProvider`:
|
|
103
105
|
|
|
104
106
|
```tsx
|
|
105
107
|
import '@adonis-agora/authkit-react/styles.css'
|
|
108
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
106
109
|
import {
|
|
110
|
+
AuthkitClientProvider,
|
|
107
111
|
AuthkitProvider,
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
createAuthkitQueryClient,
|
|
113
|
+
AuthorizedApps,
|
|
114
|
+
UserButton,
|
|
115
|
+
UserProfile,
|
|
110
116
|
} from '@adonis-agora/authkit-react'
|
|
111
117
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
<
|
|
116
|
-
|
|
118
|
+
const queryClient = createAuthkitQueryClient()
|
|
119
|
+
|
|
120
|
+
<QueryClientProvider client={queryClient}>
|
|
121
|
+
<AuthkitClientProvider>
|
|
122
|
+
<AuthkitProvider config={{ csrfToken: page.props.csrfToken }}>
|
|
123
|
+
<UserButton />
|
|
124
|
+
<UserProfile />
|
|
125
|
+
<AuthorizedApps />
|
|
126
|
+
</AuthkitProvider>
|
|
127
|
+
</AuthkitClientProvider>
|
|
128
|
+
</QueryClientProvider>
|
|
117
129
|
```
|
|
118
130
|
|
|
119
|
-
|
|
120
|
-
(
|
|
121
|
-
|
|
122
|
-
redirecionam para o IdP. Temável via CSS vars `--authkit-*`. Veja a
|
|
123
|
-
[doc de React](https://...) para detalhes.
|
|
131
|
+
Para telas próprias, use as query options com `useQuery`/`useMutation`
|
|
132
|
+
(`useMeQueryOptions`, `useAccountSessionsQueryOptions`, `useAppsQueryOptions`,
|
|
133
|
+
`useAccountOrgsQueryOptions`, …). Temável via CSS vars `--authkit-*`.
|
|
124
134
|
|
|
125
135
|
## Helpers puros
|
|
126
136
|
|
package/build/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { AuthkitClient, AuthkitClientOptions, } from './src/client/client.j
|
|
|
4
4
|
export { AuthkitClientError, createAuthkitClient, } from './src/client/client.js';
|
|
5
5
|
export type { AuthkitClientProviderProps } from './src/client/context.js';
|
|
6
6
|
export { AuthkitClientProvider, createAuthkitQueryClient, useAuthkitClient, } from './src/client/context.js';
|
|
7
|
-
export type { AcceptOrgInvitationResult, AccountAppEntry, AccountAppsResult, AccountCapabilities, AccountLoginMethodsResult, AccountMe, AccountMfaStatus, AccountOrgDetail, AccountOrgEntry, AccountOrgInvitationsResult, AccountOrgsResult, AccountPasskeysResult, AccountSecurityOverview, AccountSessionEntry, AccountSessionsResult, AccountTokensResult, ActivateOrgResult, AdminClient, AdminClientListResult, AdminGrantEntry, AdminOrgDetail, AdminOrgEntry, AdminOrgInvitation, AdminOrgListResult, AdminOrgMember, AdminOverview, AdminSessionEntry, AdminUser, AdminUserListResult, ApiErrorBody, AuditEventEntry, AuditListParams, AuditListResult, ChangePasswordInput, CreateAccountOrgInput, CreateClientInput, CreatedAccountOrgResult, CreatedClientResult, CreatedOrgInvitationResult, CreatedPatResult, CreateOrgInput, CreateRoleInput, CreateTokenInput, CreateUserInput, DailyPoint, DeactivateOrgResult, EmailChangeResult, ImpersonationPanel, InviteOrgMemberInput, KeysRotateInput, KeysRotateResult, KeysStatus, LeaveOrgResult, ListMeta, ManagedKeyInfo, MfaConfirmResult, MfaDisableResult, MfaEnrollResult, MfaRecoveryCodesResult, OkResult, PasskeyRegistrationOptions, PasskeySummaryEntry, PatEntry, PersonalAgentConnection, PersonalAgentConnectionsParams, PersonalAgentConnectionsResult, PersonalAgentEntry, PersonalAgentListStatus, PersonalAgentProtocol, PersonalAgentRegistryInput, PersonalAgentRegistryResult, PersonalAgentsOverview, RegenerateSecretResult, RemoveOrgMemberResult, RemovePasskeyResult, RequestEmailChangeInput, RevokeAllResult, RevokeAppResult, RevokeOrgInvitationResult, RevokeOthersResult, RevokeSessionResult, RevokeSessionsResult, RevokeTokenResult, RoleCatalogEntry, RoleListResult, SettingEntry, SettingListResult, UpdateClientInput, UpdateLoginMethodsResult, UpdateOrgInput, UpdateOrgMemberRoleResult, UpdateProfileInput, UpdateProfileResult, UpdateRoleInput, UpdateUserInput, UserLoginMethodsInput, UserSessionsResult, } from './src/client/types.js';
|
|
7
|
+
export type { AcceptOrgInvitationResult, AccountAgentGrant, AccountAgentsResult, AccountAppEntry, AccountAppsResult, AccountCapabilities, AccountLoginMethodsResult, AccountMe, AccountMfaStatus, AccountOrgDetail, AccountOrgEntry, AccountOrgInvitationsResult, AccountOrgsResult, AccountPasskeysResult, AccountSecurityOverview, AccountSessionEntry, AccountSessionsResult, AccountTokensResult, ActivateOrgResult, AdminClient, AdminClientListResult, AdminGrantEntry, AdminOrgDetail, AdminOrgEntry, AdminOrgInvitation, AdminOrgListResult, AdminOrgMember, AdminOverview, AdminSessionEntry, AdminUser, AdminUserListResult, ApiErrorBody, AuditEventEntry, AuditListParams, AuditListResult, ChangePasswordInput, CreateAccountOrgInput, CreateClientInput, CreatedAccountOrgResult, CreatedClientResult, CreatedOrgInvitationResult, CreatedPatResult, CreateOrgInput, CreateRoleInput, CreateTokenInput, CreateUserInput, DailyPoint, DeactivateOrgResult, DeletedResult, EmailChangeResult, ImpersonationPanel, InviteOrgMemberInput, KeysRotateInput, KeysRotateResult, KeysStatus, LeaveOrgResult, ListMeta, ManagedKeyInfo, MfaConfirmResult, MfaDisableResult, MfaEnrollResult, MfaRecoveryCodesResult, OkResult, PasskeyRegistrationOptions, PasskeySummaryEntry, PatEntry, PersonalAgentConnection, PersonalAgentConnectionsParams, PersonalAgentConnectionsResult, PersonalAgentEntry, PersonalAgentExtensionOverview, PersonalAgentListStatus, PersonalAgentPactOverview, PersonalAgentProtocol, PersonalAgentRegistryInput, PersonalAgentRegistryResult, PersonalAgentsOverview, RegenerateSecretResult, RemoveOrgMemberResult, RemovePasskeyResult, RequestEmailChangeInput, ResetPasswordResult, RevokeAllResult, RevokeAppResult, RevokeOrgInvitationResult, RevokeOthersResult, RevokeSessionResult, RevokeSessionsResult, RevokeTokenResult, RoleCatalogEntry, RoleListResult, SettingEntry, SettingListResult, UpdateClientInput, UpdateLoginMethodsResult, UpdateOrgInput, UpdateOrgMemberRoleResult, UpdateProfileInput, UpdateProfileResult, UpdateRoleInput, UpdateUserInput, UserLoginMethodsInput, UserSessionsResult, } from './src/client/types.js';
|
|
8
8
|
export type { AuthenticatedProps, GuestProps, } from './src/components/authenticated.js';
|
|
9
9
|
export { Authenticated, Guest } from './src/components/authenticated.js';
|
|
10
10
|
export type { AuthorizedAppsProps } from './src/components/authorized_apps.js';
|
|
@@ -41,16 +41,8 @@ export type { UserProfileProps } from './src/components/user_profile.js';
|
|
|
41
41
|
export { UserProfile } from './src/components/user_profile.js';
|
|
42
42
|
export type { AuthkitConfig, AuthkitEndpoints, AuthkitIdpMode, ResolvedAuthkitConfig, } from './src/config.js';
|
|
43
43
|
export { AuthkitConfigContext, buildAuthUrl, DEFAULT_CONFIG, resolveConfig, useAuthkitConfig, } from './src/config.js';
|
|
44
|
-
export type { AuthorizedApp, UseAuthorizedAppsResult, } from './src/hooks/use_authorized_apps.js';
|
|
45
|
-
export { useAuthorizedApps } from './src/hooks/use_authorized_apps.js';
|
|
46
44
|
export type { UseCanResult } from './src/hooks/use_can.js';
|
|
47
45
|
export { checkCan, invalidateCanCache, useCan } from './src/hooks/use_can.js';
|
|
48
|
-
export type { OrgInvitationEntry, UseOrgInvitationsResult, } from './src/hooks/use_org_invitations.js';
|
|
49
|
-
export { useOrgInvitations } from './src/hooks/use_org_invitations.js';
|
|
50
|
-
export type { ActiveOrgDetail, OrgMemberEntry, UseOrganizationResult, } from './src/hooks/use_organization.js';
|
|
51
|
-
export { useOrganization } from './src/hooks/use_organization.js';
|
|
52
|
-
export type { OrgEntry, UseOrganizationsResult, } from './src/hooks/use_organizations.js';
|
|
53
|
-
export { useOrganizations } from './src/hooks/use_organizations.js';
|
|
54
46
|
export type { UsePasskeyAssertionOptions, UsePasskeyAssertionResult, } from './src/hooks/use_passkey_assertion.js';
|
|
55
47
|
export { usePasskeyAssertion } from './src/hooks/use_passkey_assertion.js';
|
|
56
48
|
export type { UsePasskeyAutofillOptions } from './src/hooks/use_passkey_autofill.js';
|
|
@@ -61,18 +53,11 @@ export type { UsePasskeyRegistrationOptions, UsePasskeyRegistrationResult, } fro
|
|
|
61
53
|
export { usePasskeyRegistration } from './src/hooks/use_passkey_registration.js';
|
|
62
54
|
export type { PasswordScorer, PasswordStrengthResult, PasswordStrengthScore, UsePasswordStrengthOptions, } from './src/hooks/use_password_strength.js';
|
|
63
55
|
export { heuristicScorer, usePasswordStrength, } from './src/hooks/use_password_strength.js';
|
|
64
|
-
export
|
|
65
|
-
export { useProfile } from './src/hooks/use_profile.js';
|
|
66
|
-
export type { ResourceState } from './src/hooks/use_resource.js';
|
|
67
|
-
export { jsonRequest, useResource } from './src/hooks/use_resource.js';
|
|
68
|
-
export type { AuthSession, UseSessionsResult, } from './src/hooks/use_sessions.js';
|
|
69
|
-
export { useSessions } from './src/hooks/use_sessions.js';
|
|
56
|
+
export { jsonRequest } from './src/hooks/use_resource.js';
|
|
70
57
|
export type { SignInOptions } from './src/hooks/use_sign_in.js';
|
|
71
58
|
export { useSignIn } from './src/hooks/use_sign_in.js';
|
|
72
59
|
export type { SignOutOptions } from './src/hooks/use_sign_out.js';
|
|
73
60
|
export { useSignOut } from './src/hooks/use_sign_out.js';
|
|
74
|
-
export type { UseSwitchOrganizationResult } from './src/hooks/use_switch_organization.js';
|
|
75
|
-
export { useSwitchOrganization } from './src/hooks/use_switch_organization.js';
|
|
76
61
|
export type { UseUserResult } from './src/hooks/use_user.js';
|
|
77
62
|
export { useUser } from './src/hooks/use_user.js';
|
|
78
63
|
export type { LastLoginMethod } from './src/interaction/last_used.js';
|
|
@@ -89,7 +74,7 @@ export type { RunPasskeyAssertionDeps, RunPasskeyFlowOptions, RunPasskeyRegistra
|
|
|
89
74
|
export { runPasskeyAssertion, runPasskeyRegistration } from './src/passkey/sudo.js';
|
|
90
75
|
export type { AuthProviderProps } from './src/provider.js';
|
|
91
76
|
export { AuthContext, AuthProvider } from './src/provider.js';
|
|
92
|
-
export { useAccountAcceptOrgInvitationMutationOptions, useAccountActivateOrgMutationOptions, useAccountCreateOrgMutationOptions, useAccountDeactivateOrgMutationOptions, useAccountInviteOrgMemberMutationOptions, useAccountLeaveOrgMutationOptions, useAccountOrgInvitationsQueryOptions, useAccountOrgQueryOptions, useAccountOrgsQueryOptions, useAccountRemoveOrgMemberMutationOptions, useAccountRevokeAllSessionsMutationOptions, useAccountRevokeOrgInvitationMutationOptions, useAccountSessionsQueryOptions, useAccountUpdateOrgMemberRoleMutationOptions, useAppsQueryOptions, useCancelEmailChangeMutationOptions, useChangePasswordMutationOptions, useConfirmTotpMutationOptions, useCreateTokenMutationOptions, useDisableTotpMutationOptions, useEmailChangeMutationOptions, useEnrollTotpMutationOptions, useLoginMethodsQueryOptions, useMeQueryOptions, useMfaQueryOptions, usePasskeysQueryOptions, useRegenerateRecoveryCodesMutationOptions, useRegisterPasskeyMutationOptions, useRemovePasskeyMutationOptions, useRevokeAppMutationOptions, useRevokeOtherSessionsMutationOptions, useRevokeSessionMutationOptions, useRevokeTokenMutationOptions, useSecurityQueryOptions, useTokensQueryOptions, useUpdateLoginMethodsMutationOptions, useUpdateProfileMutationOptions, } from './src/queries/account/index.js';
|
|
77
|
+
export { useAccountAcceptOrgInvitationMutationOptions, useAccountActivateOrgMutationOptions, useAccountAgentsQueryOptions, useAccountCreateOrgMutationOptions, useAccountDeactivateOrgMutationOptions, useAccountInviteOrgMemberMutationOptions, useAccountLeaveOrgMutationOptions, useAccountOrgInvitationsQueryOptions, useAccountOrgQueryOptions, useAccountOrgsQueryOptions, useAccountRemoveOrgMemberMutationOptions, useAccountRevokeAllSessionsMutationOptions, useAccountRevokeOrgInvitationMutationOptions, useAccountSessionsQueryOptions, useAccountUpdateOrgMemberRoleMutationOptions, useAppsQueryOptions, useCancelEmailChangeMutationOptions, useChangePasswordMutationOptions, useConfirmTotpMutationOptions, useCreateTokenMutationOptions, useDisableTotpMutationOptions, useEmailChangeMutationOptions, useEnrollTotpMutationOptions, useLoginMethodsQueryOptions, useMeQueryOptions, useMfaQueryOptions, usePasskeysQueryOptions, useRegenerateRecoveryCodesMutationOptions, useRegisterPasskeyMutationOptions, useRemovePasskeyMutationOptions, useRevokeAccountAgentMutationOptions, useRevokeAppMutationOptions, useRevokeOtherSessionsMutationOptions, useRevokeSessionMutationOptions, useRevokeTokenMutationOptions, useSecurityQueryOptions, useTokensQueryOptions, useUpdateLoginMethodsMutationOptions, useUpdateProfileMutationOptions, } from './src/queries/account/index.js';
|
|
93
78
|
export { useAddOrgMemberMutationOptions, useAuditQueryOptions, useClientQueryOptions, useClientsQueryOptions, useCreateClientMutationOptions, useCreateOrgInvitationMutationOptions, useCreateOrgMutationOptions, useCreateRoleMutationOptions, useCreateUserMutationOptions, useDeleteClientMutationOptions, useDeleteOrgMutationOptions, useDeleteRoleMutationOptions, useDeleteUserMutationOptions, useDisableUserMutationOptions, useEnableUserMutationOptions, useImpersonationQueryOptions, useKeysQueryOptions, useOrgQueryOptions, useOrgsQueryOptions, useOverviewQueryOptions, usePersonalAgentConnectionsQueryOptions, usePersonalAgentsQueryOptions, useRegenerateClientSecretMutationOptions, useRemoveOrgMemberMutationOptions, useRemovePersonalAgentEntryMutationOptions, useRemoveSettingMutationOptions, useResetPasswordMutationOptions, useRevokeAllSessionsMutationOptions, useRevokeOrgInvitationMutationOptions, useRevokePersonalAgentConnectionMutationOptions, useRevokeUserSessionsMutationOptions, useRolesQueryOptions, useRotateKeysMutationOptions, useSessionsQueryOptions, useSetPersonalAgentStatusMutationOptions, useSetSettingMutationOptions, useSettingsQueryOptions, useUpdateClientMutationOptions, useUpdateOrgMemberRoleMutationOptions, useUpdateOrgMutationOptions, useUpdateRoleMutationOptions, useUpdateUserMutationOptions, useUserQueryOptions, useUserSessionsQueryOptions, useUsersQueryOptions, } from './src/queries/admin/index.js';
|
|
94
79
|
export { authkitKeys } from './src/queries/keys.js';
|
|
95
80
|
export { hasAllGlobalRoles, hasAnyGlobalRole, hasGlobalRole, } from './src/roles.js';
|
package/build/index.js
CHANGED
|
@@ -19,22 +19,15 @@ export { SignOutButton } from './src/components/sign_out_button.js';
|
|
|
19
19
|
export { UserButton } from './src/components/user_button.js';
|
|
20
20
|
export { UserProfile } from './src/components/user_profile.js';
|
|
21
21
|
export { AuthkitConfigContext, buildAuthUrl, DEFAULT_CONFIG, resolveConfig, useAuthkitConfig, } from './src/config.js';
|
|
22
|
-
export { useAuthorizedApps } from './src/hooks/use_authorized_apps.js';
|
|
23
22
|
export { checkCan, invalidateCanCache, useCan } from './src/hooks/use_can.js';
|
|
24
|
-
export { useOrgInvitations } from './src/hooks/use_org_invitations.js';
|
|
25
|
-
export { useOrganization } from './src/hooks/use_organization.js';
|
|
26
|
-
export { useOrganizations } from './src/hooks/use_organizations.js';
|
|
27
23
|
export { usePasskeyAssertion } from './src/hooks/use_passkey_assertion.js';
|
|
28
24
|
export { usePasskeyAutofill } from './src/hooks/use_passkey_autofill.js';
|
|
29
25
|
export { usePasskeyLogin } from './src/hooks/use_passkey_login.js';
|
|
30
26
|
export { usePasskeyRegistration } from './src/hooks/use_passkey_registration.js';
|
|
31
27
|
export { heuristicScorer, usePasswordStrength, } from './src/hooks/use_password_strength.js';
|
|
32
|
-
export {
|
|
33
|
-
export { jsonRequest, useResource } from './src/hooks/use_resource.js';
|
|
34
|
-
export { useSessions } from './src/hooks/use_sessions.js';
|
|
28
|
+
export { jsonRequest } from './src/hooks/use_resource.js';
|
|
35
29
|
export { useSignIn } from './src/hooks/use_sign_in.js';
|
|
36
30
|
export { useSignOut } from './src/hooks/use_sign_out.js';
|
|
37
|
-
export { useSwitchOrganization } from './src/hooks/use_switch_organization.js';
|
|
38
31
|
export { useUser } from './src/hooks/use_user.js';
|
|
39
32
|
export { isLastUsedLoginMethod } from './src/interaction/last_used.js';
|
|
40
33
|
export { interactionUrls, OTP_CODE_FIELD, oauthRedirectUrl } from './src/interaction/urls.js';
|
|
@@ -43,7 +36,7 @@ export { submitClassicForm } from './src/passkey/classic_form.js';
|
|
|
43
36
|
export { registerPasskeyJson } from './src/passkey/json_registration.js';
|
|
44
37
|
export { runPasskeyAssertion, runPasskeyRegistration } from './src/passkey/sudo.js';
|
|
45
38
|
export { AuthContext, AuthProvider } from './src/provider.js';
|
|
46
|
-
export { useAccountAcceptOrgInvitationMutationOptions, useAccountActivateOrgMutationOptions, useAccountCreateOrgMutationOptions, useAccountDeactivateOrgMutationOptions, useAccountInviteOrgMemberMutationOptions, useAccountLeaveOrgMutationOptions, useAccountOrgInvitationsQueryOptions, useAccountOrgQueryOptions, useAccountOrgsQueryOptions, useAccountRemoveOrgMemberMutationOptions, useAccountRevokeAllSessionsMutationOptions, useAccountRevokeOrgInvitationMutationOptions, useAccountSessionsQueryOptions, useAccountUpdateOrgMemberRoleMutationOptions, useAppsQueryOptions, useCancelEmailChangeMutationOptions, useChangePasswordMutationOptions, useConfirmTotpMutationOptions, useCreateTokenMutationOptions, useDisableTotpMutationOptions, useEmailChangeMutationOptions, useEnrollTotpMutationOptions, useLoginMethodsQueryOptions, useMeQueryOptions, useMfaQueryOptions, usePasskeysQueryOptions, useRegenerateRecoveryCodesMutationOptions, useRegisterPasskeyMutationOptions, useRemovePasskeyMutationOptions, useRevokeAppMutationOptions, useRevokeOtherSessionsMutationOptions, useRevokeSessionMutationOptions, useRevokeTokenMutationOptions, useSecurityQueryOptions, useTokensQueryOptions, useUpdateLoginMethodsMutationOptions, useUpdateProfileMutationOptions, } from './src/queries/account/index.js';
|
|
39
|
+
export { useAccountAcceptOrgInvitationMutationOptions, useAccountActivateOrgMutationOptions, useAccountAgentsQueryOptions, useAccountCreateOrgMutationOptions, useAccountDeactivateOrgMutationOptions, useAccountInviteOrgMemberMutationOptions, useAccountLeaveOrgMutationOptions, useAccountOrgInvitationsQueryOptions, useAccountOrgQueryOptions, useAccountOrgsQueryOptions, useAccountRemoveOrgMemberMutationOptions, useAccountRevokeAllSessionsMutationOptions, useAccountRevokeOrgInvitationMutationOptions, useAccountSessionsQueryOptions, useAccountUpdateOrgMemberRoleMutationOptions, useAppsQueryOptions, useCancelEmailChangeMutationOptions, useChangePasswordMutationOptions, useConfirmTotpMutationOptions, useCreateTokenMutationOptions, useDisableTotpMutationOptions, useEmailChangeMutationOptions, useEnrollTotpMutationOptions, useLoginMethodsQueryOptions, useMeQueryOptions, useMfaQueryOptions, usePasskeysQueryOptions, useRegenerateRecoveryCodesMutationOptions, useRegisterPasskeyMutationOptions, useRemovePasskeyMutationOptions, useRevokeAccountAgentMutationOptions, useRevokeAppMutationOptions, useRevokeOtherSessionsMutationOptions, useRevokeSessionMutationOptions, useRevokeTokenMutationOptions, useSecurityQueryOptions, useTokensQueryOptions, useUpdateLoginMethodsMutationOptions, useUpdateProfileMutationOptions, } from './src/queries/account/index.js';
|
|
47
40
|
export { useAddOrgMemberMutationOptions, useAuditQueryOptions, useClientQueryOptions, useClientsQueryOptions, useCreateClientMutationOptions, useCreateOrgInvitationMutationOptions, useCreateOrgMutationOptions, useCreateRoleMutationOptions, useCreateUserMutationOptions, useDeleteClientMutationOptions, useDeleteOrgMutationOptions, useDeleteRoleMutationOptions, useDeleteUserMutationOptions, useDisableUserMutationOptions, useEnableUserMutationOptions, useImpersonationQueryOptions, useKeysQueryOptions, useOrgQueryOptions, useOrgsQueryOptions, useOverviewQueryOptions, usePersonalAgentConnectionsQueryOptions, usePersonalAgentsQueryOptions, useRegenerateClientSecretMutationOptions, useRemoveOrgMemberMutationOptions, useRemovePersonalAgentEntryMutationOptions, useRemoveSettingMutationOptions, useResetPasswordMutationOptions, useRevokeAllSessionsMutationOptions, useRevokeOrgInvitationMutationOptions, useRevokePersonalAgentConnectionMutationOptions, useRevokeUserSessionsMutationOptions, useRolesQueryOptions, useRotateKeysMutationOptions, useSessionsQueryOptions, useSetPersonalAgentStatusMutationOptions, useSetSettingMutationOptions, useSettingsQueryOptions, useUpdateClientMutationOptions, useUpdateOrgMemberRoleMutationOptions, useUpdateOrgMutationOptions, useUpdateRoleMutationOptions, useUpdateUserMutationOptions, useUserQueryOptions, useUserSessionsQueryOptions, useUsersQueryOptions, } from './src/queries/admin/index.js';
|
|
48
41
|
export { authkitKeys } from './src/queries/keys.js';
|
|
49
42
|
export { hasAllGlobalRoles, hasAnyGlobalRole, hasGlobalRole, } from './src/roles.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AcceptOrgInvitationResult, AccountAppsResult, AccountLoginMethodsResult, AccountMe, AccountMfaStatus, AccountOrgDetail, AccountOrgInvitationsResult, AccountOrgsResult, AccountPasskeysResult, AccountSecurityOverview, AccountSessionsResult, AccountTokensResult, ActivateOrgResult, AdminClient, AdminClientListResult, AdminOrgDetail, AdminOrgEntry, AdminOrgInvitation, AdminOrgListResult, AdminOverview, AdminUser, AdminUserListResult, AuditListParams, AuditListResult, ChangePasswordInput, CreateAccountOrgInput, CreateClientInput, CreatedAccountOrgResult, CreatedClientResult, CreatedOrgInvitationResult, CreatedPatResult, CreateOrgInput, CreateRoleInput, CreateTokenInput, CreateUserInput, DeactivateOrgResult, EmailChangeResult, ImpersonationPanel, InviteOrgMemberInput, KeysRotateInput, KeysRotateResult, KeysStatus, LeaveOrgResult, MfaConfirmResult, MfaDisableResult, MfaEnrollResult, MfaRecoveryCodesResult, OkResult, PasskeyRegistrationOptions, PersonalAgentConnectionsParams, PersonalAgentConnectionsResult, PersonalAgentRegistryInput, PersonalAgentRegistryResult, PersonalAgentsOverview, RegenerateSecretResult, RemoveOrgMemberResult, RemovePasskeyResult, RequestEmailChangeInput, RevokeAllResult, RevokeAppResult, RevokeOrgInvitationResult, RevokeOthersResult, RevokeSessionResult, RevokeSessionsResult, RevokeTokenResult, RoleCatalogEntry, RoleListResult, SettingEntry, SettingListResult, UpdateClientInput, UpdateLoginMethodsResult, UpdateOrgInput, UpdateOrgMemberRoleResult, UpdateProfileInput, UpdateProfileResult, UpdateRoleInput, UpdateUserInput, UserLoginMethodsInput, UserSessionsResult } from './types.js';
|
|
1
|
+
import type { AcceptOrgInvitationResult, AccountAgentsResult, AccountAppsResult, AccountLoginMethodsResult, AccountMe, AccountMfaStatus, AccountOrgDetail, AccountOrgInvitationsResult, AccountOrgsResult, AccountPasskeysResult, AccountSecurityOverview, AccountSessionsResult, AccountTokensResult, ActivateOrgResult, AdminClient, AdminClientListResult, AdminOrgDetail, AdminOrgEntry, AdminOrgInvitation, AdminOrgListResult, AdminOverview, AdminUser, AdminUserListResult, AuditListParams, AuditListResult, ChangePasswordInput, CreateAccountOrgInput, CreateClientInput, CreatedAccountOrgResult, CreatedClientResult, CreatedOrgInvitationResult, CreatedPatResult, CreateOrgInput, CreateRoleInput, CreateTokenInput, CreateUserInput, DeactivateOrgResult, DeletedResult, EmailChangeResult, ImpersonationPanel, InviteOrgMemberInput, KeysRotateInput, KeysRotateResult, KeysStatus, LeaveOrgResult, MfaConfirmResult, MfaDisableResult, MfaEnrollResult, MfaRecoveryCodesResult, OkResult, PasskeyRegistrationOptions, PersonalAgentConnectionsParams, PersonalAgentConnectionsResult, PersonalAgentRegistryInput, PersonalAgentRegistryResult, PersonalAgentsOverview, RegenerateSecretResult, RemoveOrgMemberResult, RemovePasskeyResult, RequestEmailChangeInput, ResetPasswordResult, RevokeAllResult, RevokeAppResult, RevokeOrgInvitationResult, RevokeOthersResult, RevokeSessionResult, RevokeSessionsResult, RevokeTokenResult, RoleCatalogEntry, RoleListResult, SettingEntry, SettingListResult, UpdateClientInput, UpdateLoginMethodsResult, UpdateOrgInput, UpdateOrgMemberRoleResult, UpdateProfileInput, UpdateProfileResult, UpdateRoleInput, UpdateUserInput, UserLoginMethodsInput, UserSessionsResult } from './types.js';
|
|
2
2
|
export declare class AuthkitClientError extends Error {
|
|
3
3
|
readonly status: number;
|
|
4
4
|
readonly code?: string | undefined;
|
|
@@ -39,22 +39,10 @@ declare class AuthkitClient {
|
|
|
39
39
|
invited?: boolean;
|
|
40
40
|
}>;
|
|
41
41
|
readonly update: (id: string, data: UpdateUserInput) => Promise<AdminUser>;
|
|
42
|
-
readonly disable: (id: string) => Promise<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
readonly enable: (id: string) => Promise<{
|
|
47
|
-
id: string;
|
|
48
|
-
disabled: false;
|
|
49
|
-
}>;
|
|
50
|
-
readonly resetPassword: (id: string) => Promise<{
|
|
51
|
-
id: string;
|
|
52
|
-
sent: boolean;
|
|
53
|
-
}>;
|
|
54
|
-
readonly remove: (id: string) => Promise<{
|
|
55
|
-
id: string;
|
|
56
|
-
deleted: boolean;
|
|
57
|
-
}>;
|
|
42
|
+
readonly disable: (id: string) => Promise<AdminUser>;
|
|
43
|
+
readonly enable: (id: string) => Promise<AdminUser>;
|
|
44
|
+
readonly resetPassword: (id: string) => Promise<ResetPasswordResult>;
|
|
45
|
+
readonly remove: (id: string) => Promise<DeletedResult>;
|
|
58
46
|
readonly getSessions: (id: string) => Promise<UserSessionsResult>;
|
|
59
47
|
readonly revokeSessions: (id: string) => Promise<RevokeSessionsResult>;
|
|
60
48
|
};
|
|
@@ -67,10 +55,7 @@ declare class AuthkitClient {
|
|
|
67
55
|
readonly get: (id: string) => Promise<AdminClient>;
|
|
68
56
|
readonly create: (data?: CreateClientInput) => Promise<CreatedClientResult>;
|
|
69
57
|
readonly update: (id: string, data?: UpdateClientInput) => Promise<AdminClient>;
|
|
70
|
-
readonly remove: (id: string) => Promise<
|
|
71
|
-
clientId: string;
|
|
72
|
-
deleted: boolean;
|
|
73
|
-
}>;
|
|
58
|
+
readonly remove: (id: string) => Promise<DeletedResult>;
|
|
74
59
|
readonly regenerateSecret: (id: string) => Promise<RegenerateSecretResult>;
|
|
75
60
|
};
|
|
76
61
|
readonly roles: {
|
|
@@ -162,6 +147,12 @@ declare class AuthkitClient {
|
|
|
162
147
|
readonly list: () => Promise<AccountAppsResult>;
|
|
163
148
|
readonly revoke: (clientId: string) => Promise<RevokeAppResult>;
|
|
164
149
|
};
|
|
150
|
+
readonly agents: {
|
|
151
|
+
readonly list: () => Promise<AccountAgentsResult>;
|
|
152
|
+
readonly revoke: (grantId: string) => Promise<{
|
|
153
|
+
ok: true;
|
|
154
|
+
}>;
|
|
155
|
+
};
|
|
165
156
|
readonly mfa: (() => Promise<AccountMfaStatus>) & {
|
|
166
157
|
enroll: () => Promise<MfaEnrollResult>;
|
|
167
158
|
confirm: (code: string) => Promise<MfaConfirmResult>;
|
|
@@ -13,16 +13,6 @@ export class AuthkitClientError extends Error {
|
|
|
13
13
|
isUnauthorized;
|
|
14
14
|
}
|
|
15
15
|
const MUTATING = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
|
|
16
|
-
function resolveWindow() {
|
|
17
|
-
try {
|
|
18
|
-
if (typeof window === 'undefined')
|
|
19
|
-
return null;
|
|
20
|
-
return window.__AUTHKIT__ ?? null;
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
16
|
function toQueryString(params) {
|
|
27
17
|
const parts = [];
|
|
28
18
|
for (const [k, v] of Object.entries(params)) {
|
|
@@ -38,10 +28,9 @@ class AuthkitClient {
|
|
|
38
28
|
_csrfToken;
|
|
39
29
|
_fetch;
|
|
40
30
|
constructor(opts = {}) {
|
|
41
|
-
|
|
42
|
-
this._baseUrl = opts.baseUrl ?? win?.endpoints.api;
|
|
31
|
+
this._baseUrl = opts.baseUrl;
|
|
43
32
|
this._accountBaseUrl = opts.accountBaseUrl ?? '/account/api';
|
|
44
|
-
this._csrfToken = opts.csrfToken
|
|
33
|
+
this._csrfToken = opts.csrfToken;
|
|
45
34
|
this._fetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
46
35
|
}
|
|
47
36
|
async request(method, url, body, extraHeaders) {
|
|
@@ -101,8 +90,7 @@ class AuthkitClient {
|
|
|
101
90
|
}
|
|
102
91
|
b(path) {
|
|
103
92
|
if (!this._baseUrl) {
|
|
104
|
-
throw new Error('[AuthkitClient] admin base URL ausente: passe `baseUrl` em createAuthkitClient({ baseUrl }) ' +
|
|
105
|
-
'ou use o client onde window.__AUTHKIT__ está injetado (console admin). ' +
|
|
93
|
+
throw new Error('[AuthkitClient] admin base URL ausente: passe `baseUrl` em createAuthkitClient({ baseUrl }). ' +
|
|
106
94
|
'Telas que só usam client.account.* não precisam de baseUrl.');
|
|
107
95
|
}
|
|
108
96
|
return `${this._baseUrl}${path}`;
|
|
@@ -213,6 +201,10 @@ class AuthkitClient {
|
|
|
213
201
|
list: () => this.get(this.a('/apps')),
|
|
214
202
|
revoke: (clientId) => this.delete(this.a(`/apps/${encodeURIComponent(clientId)}`)),
|
|
215
203
|
},
|
|
204
|
+
agents: {
|
|
205
|
+
list: () => this.get(this.a('/agents')),
|
|
206
|
+
revoke: (grantId) => this.delete(this.a(`/agents/${encodeURIComponent(grantId)}`)),
|
|
207
|
+
},
|
|
216
208
|
mfa: Object.assign(() => this.get(this.a('/mfa')), {
|
|
217
209
|
enroll: () => this.post(this.a('/mfa/totp/enroll')),
|
|
218
210
|
confirm: (code) => this.post(this.a('/mfa/totp/confirm'), { code }),
|
|
@@ -25,14 +25,12 @@ export interface AdminUserListResult {
|
|
|
25
25
|
}
|
|
26
26
|
export interface CreateUserInput {
|
|
27
27
|
email: string;
|
|
28
|
-
name?: string
|
|
29
|
-
password?: string
|
|
28
|
+
name?: string;
|
|
29
|
+
password?: string;
|
|
30
30
|
invite?: boolean;
|
|
31
31
|
}
|
|
32
32
|
export interface UpdateUserInput {
|
|
33
33
|
globalRoles?: string[];
|
|
34
|
-
name?: string | null;
|
|
35
|
-
avatarUrl?: string | null;
|
|
36
34
|
}
|
|
37
35
|
export interface AdminSessionEntry {
|
|
38
36
|
id: string;
|
|
@@ -71,13 +69,15 @@ export interface AdminSessionListResult {
|
|
|
71
69
|
export interface AdminClient {
|
|
72
70
|
clientId: string;
|
|
73
71
|
confidential: boolean;
|
|
74
|
-
|
|
72
|
+
grantTypes: string[];
|
|
75
73
|
redirectUris: string[];
|
|
76
74
|
postLogoutRedirectUris: string[];
|
|
77
75
|
tokenEndpointAuthMethod: string;
|
|
78
76
|
applicationType?: 'web' | 'native';
|
|
79
77
|
backchannelLogoutUri: string | null;
|
|
80
78
|
backchannelLogoutSessionRequired: boolean;
|
|
79
|
+
clientName: string | null;
|
|
80
|
+
logoUri: string | null;
|
|
81
81
|
}
|
|
82
82
|
export interface AdminClientListResult {
|
|
83
83
|
data: AdminClient[];
|
|
@@ -100,8 +100,14 @@ export interface CreateClientInput {
|
|
|
100
100
|
applicationType?: 'web' | 'native';
|
|
101
101
|
backchannelLogoutUri?: string;
|
|
102
102
|
backchannelLogoutSessionRequired?: boolean;
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
clientName?: string;
|
|
104
|
+
logoUri?: string;
|
|
105
|
+
}
|
|
106
|
+
export type UpdateClientInput = Omit<CreateClientInput, 'backchannelLogoutUri' | 'clientName' | 'logoUri'> & {
|
|
107
|
+
backchannelLogoutUri?: string | null;
|
|
108
|
+
clientName?: string | null;
|
|
109
|
+
logoUri?: string | null;
|
|
110
|
+
};
|
|
105
111
|
export interface RoleCatalogEntry {
|
|
106
112
|
name: string;
|
|
107
113
|
description?: string;
|
|
@@ -188,6 +194,15 @@ export interface SettingEntry {
|
|
|
188
194
|
}
|
|
189
195
|
export interface SettingListResult {
|
|
190
196
|
data: SettingEntry[];
|
|
197
|
+
locked: string[];
|
|
198
|
+
}
|
|
199
|
+
export interface DeletedResult {
|
|
200
|
+
ok: true;
|
|
201
|
+
deleted: string;
|
|
202
|
+
}
|
|
203
|
+
export interface ResetPasswordResult {
|
|
204
|
+
ok: true;
|
|
205
|
+
email: string;
|
|
191
206
|
}
|
|
192
207
|
export interface ImpersonationPanel {
|
|
193
208
|
targetUserId: string;
|
|
@@ -308,6 +323,8 @@ export interface RevokeAllResult {
|
|
|
308
323
|
}
|
|
309
324
|
export interface AccountAppEntry {
|
|
310
325
|
clientId: string;
|
|
326
|
+
name: string;
|
|
327
|
+
logoUrl: string | null;
|
|
311
328
|
accessTokens: number;
|
|
312
329
|
refreshTokens: number;
|
|
313
330
|
}
|
|
@@ -315,6 +332,21 @@ export interface AccountAppsResult {
|
|
|
315
332
|
supported: boolean;
|
|
316
333
|
apps: AccountAppEntry[];
|
|
317
334
|
}
|
|
335
|
+
export interface AccountAgentGrant {
|
|
336
|
+
id: string;
|
|
337
|
+
clientId: string;
|
|
338
|
+
protocol: PersonalAgentProtocol;
|
|
339
|
+
scopes: Array<{
|
|
340
|
+
id: string;
|
|
341
|
+
description: string;
|
|
342
|
+
}>;
|
|
343
|
+
createdAt: string;
|
|
344
|
+
updatedAt: string;
|
|
345
|
+
expiresAt: string;
|
|
346
|
+
}
|
|
347
|
+
export interface AccountAgentsResult {
|
|
348
|
+
agents: AccountAgentGrant[];
|
|
349
|
+
}
|
|
318
350
|
export interface RevokeAppResult {
|
|
319
351
|
ok: boolean;
|
|
320
352
|
[key: string]: unknown;
|
|
@@ -536,7 +568,7 @@ export interface KeysRotateResult {
|
|
|
536
568
|
retiredKids: string[];
|
|
537
569
|
keptKids: string[];
|
|
538
570
|
}
|
|
539
|
-
export type PersonalAgentProtocol = 'pact' |
|
|
571
|
+
export type PersonalAgentProtocol = 'pact' | (string & {});
|
|
540
572
|
export type PersonalAgentListStatus = 'allowed' | 'blocked';
|
|
541
573
|
export interface PersonalAgentEntry {
|
|
542
574
|
protocol: PersonalAgentProtocol;
|
|
@@ -555,18 +587,23 @@ export interface PersonalAgentEntry {
|
|
|
555
587
|
}
|
|
556
588
|
export interface PersonalAgentsOverview {
|
|
557
589
|
protocols: {
|
|
558
|
-
pact:
|
|
559
|
-
|
|
560
|
-
hostResolver: boolean;
|
|
561
|
-
} | null;
|
|
562
|
-
poppy: {
|
|
563
|
-
requireRegistration: boolean;
|
|
564
|
-
hostResolver: boolean;
|
|
565
|
-
allowInsecureClientIds: boolean;
|
|
566
|
-
} | null;
|
|
590
|
+
pact: PersonalAgentPactOverview | null;
|
|
591
|
+
[protocol: string]: PersonalAgentPactOverview | PersonalAgentExtensionOverview | null;
|
|
567
592
|
};
|
|
568
593
|
agents: PersonalAgentEntry[];
|
|
569
594
|
}
|
|
595
|
+
export interface PersonalAgentPactOverview {
|
|
596
|
+
open: boolean;
|
|
597
|
+
hostResolver: boolean;
|
|
598
|
+
}
|
|
599
|
+
export interface PersonalAgentExtensionOverview {
|
|
600
|
+
label: string;
|
|
601
|
+
requireRegistration: boolean;
|
|
602
|
+
hostResolver: boolean;
|
|
603
|
+
allowHttpIdentifiers: boolean;
|
|
604
|
+
identifierLabel: string;
|
|
605
|
+
identifierPlaceholder: string | null;
|
|
606
|
+
}
|
|
570
607
|
export interface PersonalAgentConnection {
|
|
571
608
|
id: string;
|
|
572
609
|
protocol: PersonalAgentProtocol;
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
3
|
import { createElement } from 'react';
|
|
3
4
|
import { useAuthkitConfig } from '../config.js';
|
|
4
|
-
import {
|
|
5
|
+
import { useAppsQueryOptions, useRevokeAppMutationOptions } from '../queries/account/index.js';
|
|
6
|
+
import { authkitKeys } from '../queries/keys.js';
|
|
5
7
|
function AuthorizedAppsInner({ className, revokeLabel = 'Revogar', emptyLabel = 'Nenhum app autorizado.', }) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
+
const qc = useQueryClient();
|
|
9
|
+
const query = useQuery(useAppsQueryOptions());
|
|
10
|
+
const revoke = useMutation({
|
|
11
|
+
...useRevokeAppMutationOptions(),
|
|
12
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: authkitKeys.account.apps() }),
|
|
13
|
+
});
|
|
14
|
+
if (query.isLoading && !query.data) {
|
|
8
15
|
return createElement('div', { className: 'authkit-apps__loading' }, 'Carregando…');
|
|
9
16
|
}
|
|
10
|
-
if (error) {
|
|
11
|
-
return createElement('p', { className: 'authkit-error', role: 'alert' }, error.message);
|
|
17
|
+
if (query.error) {
|
|
18
|
+
return createElement('p', { className: 'authkit-error', role: 'alert' }, query.error.message);
|
|
12
19
|
}
|
|
13
|
-
const apps = data ?? [];
|
|
20
|
+
const apps = query.data?.apps ?? [];
|
|
14
21
|
if (apps.length === 0) {
|
|
15
22
|
return createElement('p', { className: 'authkit-apps__empty' }, emptyLabel);
|
|
16
23
|
}
|
|
17
24
|
return createElement('ul', { className: ['authkit-apps', className].filter(Boolean).join(' ') }, ...apps.map((app) => createElement('li', { key: app.clientId, className: 'authkit-apps__item' }, createElement('div', { className: 'authkit-apps__info' }, app.logoUrl
|
|
18
|
-
? createElement('img', {
|
|
19
|
-
|
|
20
|
-
src: app.logoUrl,
|
|
21
|
-
alt: '',
|
|
22
|
-
})
|
|
23
|
-
: null, createElement('span', { className: 'authkit-apps__name' }, app.name ?? app.clientId)), createElement('button', {
|
|
25
|
+
? createElement('img', { className: 'authkit-apps__logo', src: app.logoUrl, alt: '' })
|
|
26
|
+
: null, createElement('span', { className: 'authkit-apps__name' }, app.name || app.clientId)), createElement('button', {
|
|
24
27
|
type: 'button',
|
|
25
28
|
className: 'authkit-button authkit-button--danger',
|
|
26
|
-
|
|
29
|
+
disabled: revoke.isPending,
|
|
30
|
+
onClick: () => revoke.mutate(app.clientId),
|
|
27
31
|
}, revokeLabel))));
|
|
28
32
|
}
|
|
29
33
|
export function AuthorizedApps(props) {
|
|
@@ -1,61 +1,53 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
3
|
import { createElement, useState } from 'react';
|
|
3
4
|
import { useAuthkitConfig } from '../config.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { jsonRequest } from '../hooks/use_resource.js';
|
|
5
|
+
import { useAccountInviteOrgMemberMutationOptions, useAccountLeaveOrgMutationOptions, useAccountOrgQueryOptions, useAccountOrgsQueryOptions, } from '../queries/account/index.js';
|
|
6
|
+
import { authkitKeys } from '../queries/keys.js';
|
|
7
7
|
import { useAuth } from '../use_auth.js';
|
|
8
8
|
function OrganizationProfileInner({ inviteLabel = 'Convidar membro', leaveLabel = 'Sair da organização', className, }) {
|
|
9
9
|
const { isAuthenticated } = useAuth();
|
|
10
|
-
const
|
|
11
|
-
const {
|
|
12
|
-
const
|
|
10
|
+
const qc = useQueryClient();
|
|
11
|
+
const orgs = useQuery({ ...useAccountOrgsQueryOptions(), enabled: isAuthenticated });
|
|
12
|
+
const activeOrgId = orgs.data?.activeOrgId ?? null;
|
|
13
|
+
const orgQuery = useAccountOrgQueryOptions(activeOrgId ?? '');
|
|
14
|
+
const detail = useQuery({ ...orgQuery, enabled: isAuthenticated && activeOrgId !== null });
|
|
15
|
+
const invite = useMutation({
|
|
16
|
+
...useAccountInviteOrgMemberMutationOptions(),
|
|
17
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: orgQuery.queryKey }),
|
|
18
|
+
});
|
|
19
|
+
const leave = useMutation({
|
|
20
|
+
...useAccountLeaveOrgMutationOptions(),
|
|
21
|
+
onSuccess: () => Promise.all([
|
|
22
|
+
qc.invalidateQueries({ queryKey: authkitKeys.account.orgs() }),
|
|
23
|
+
qc.invalidateQueries({ queryKey: authkitKeys.account.me() }),
|
|
24
|
+
]),
|
|
25
|
+
});
|
|
13
26
|
const [inviteEmail, setInviteEmail] = useState('');
|
|
14
27
|
const [inviteRole, setInviteRole] = useState('member');
|
|
15
|
-
const [inviteLoading, setInviteLoading] = useState(false);
|
|
16
|
-
const [inviteError, setInviteError] = useState(null);
|
|
17
28
|
if (!isAuthenticated || !activeOrgId)
|
|
18
29
|
return null;
|
|
19
|
-
if (
|
|
30
|
+
if (detail.isLoading)
|
|
20
31
|
return createElement('div', { className: 'authkit-org-profile__loading' }, 'Carregando…');
|
|
21
|
-
if (error)
|
|
22
|
-
return createElement('div', { className: 'authkit-error' }, error.message);
|
|
32
|
+
if (detail.error)
|
|
33
|
+
return createElement('div', { className: 'authkit-error' }, detail.error.message);
|
|
34
|
+
const org = detail.data;
|
|
23
35
|
if (!org)
|
|
24
36
|
return null;
|
|
25
|
-
const base = config.endpoints.orgs.replace('/json', '');
|
|
26
37
|
const handleInvite = async (e) => {
|
|
27
38
|
e.preventDefault();
|
|
28
39
|
if (!inviteEmail.trim())
|
|
29
40
|
return;
|
|
30
|
-
setInviteLoading(true);
|
|
31
|
-
setInviteError(null);
|
|
32
41
|
try {
|
|
33
|
-
await
|
|
34
|
-
method: 'POST',
|
|
35
|
-
body: JSON.stringify({ email: inviteEmail.trim(), role: inviteRole }),
|
|
36
|
-
csrfToken: config.csrfToken,
|
|
37
|
-
});
|
|
42
|
+
await invite.mutateAsync({ orgId: activeOrgId, email: inviteEmail.trim(), role: inviteRole });
|
|
38
43
|
setInviteEmail('');
|
|
39
|
-
await actions.refetch();
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
setInviteError(err);
|
|
43
|
-
}
|
|
44
|
-
finally {
|
|
45
|
-
setInviteLoading(false);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const handleLeave = async () => {
|
|
49
|
-
try {
|
|
50
|
-
await jsonRequest(`${base}/${encodeURIComponent(activeOrgId)}/leave`, {
|
|
51
|
-
method: 'POST',
|
|
52
|
-
csrfToken: config.csrfToken,
|
|
53
|
-
});
|
|
54
|
-
await orgListActions.refetch();
|
|
55
44
|
}
|
|
56
45
|
catch {
|
|
57
46
|
}
|
|
58
47
|
};
|
|
48
|
+
const handleLeave = () => {
|
|
49
|
+
leave.mutate(activeOrgId);
|
|
50
|
+
};
|
|
59
51
|
const memberList = createElement('div', { className: 'authkit-org-profile__members' }, createElement('h3', { className: 'authkit-org-profile__section-title' }, 'Membros'), ...(org.members.length === 0
|
|
60
52
|
? [createElement('p', { className: 'authkit-org-profile__empty' }, 'Nenhum membro.')]
|
|
61
53
|
: org.members.map((m) => createElement('div', { key: m.accountId, className: 'authkit-org-profile__member' }, createElement('div', { className: 'authkit-org-profile__member-info' }, createElement('span', { className: 'authkit-org-profile__member-email' }, m.email ?? m.accountId), createElement('span', { className: 'authkit-org-profile__member-role' }, m.role))))));
|
|
@@ -71,13 +63,13 @@ function OrganizationProfileInner({ inviteLabel = 'Convidar membro', leaveLabel
|
|
|
71
63
|
placeholder: 'Papel (ex: member)',
|
|
72
64
|
value: inviteRole,
|
|
73
65
|
onChange: (e) => setInviteRole(e.target.value),
|
|
74
|
-
}),
|
|
75
|
-
? createElement('p', { className: 'authkit-error', role: 'alert' },
|
|
66
|
+
}), invite.error
|
|
67
|
+
? createElement('p', { className: 'authkit-error', role: 'alert' }, invite.error.message)
|
|
76
68
|
: null, createElement('button', {
|
|
77
69
|
type: 'submit',
|
|
78
70
|
className: 'authkit-button authkit-button--primary',
|
|
79
|
-
disabled:
|
|
80
|
-
},
|
|
71
|
+
disabled: invite.isPending,
|
|
72
|
+
}, invite.isPending ? 'Enviando…' : inviteLabel))
|
|
81
73
|
: null;
|
|
82
74
|
const leaveButton = createElement('button', {
|
|
83
75
|
type: 'button',
|