@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.
Files changed (36) hide show
  1. package/CHANGELOG.md +699 -0
  2. package/README.md +29 -19
  3. package/build/index.d.ts +3 -18
  4. package/build/index.js +2 -9
  5. package/build/src/client/client.d.ts +12 -21
  6. package/build/src/client/client.js +7 -15
  7. package/build/src/client/types.d.ts +54 -17
  8. package/build/src/components/authorized_apps.js +17 -13
  9. package/build/src/components/organization_profile.js +31 -39
  10. package/build/src/components/organization_switcher.js +25 -9
  11. package/build/src/components/user_profile.js +13 -7
  12. package/build/src/config.d.ts +0 -6
  13. package/build/src/config.js +0 -12
  14. package/build/src/hooks/use_resource.d.ts +0 -8
  15. package/build/src/hooks/use_resource.js +0 -22
  16. package/build/src/queries/account/index.d.ts +11 -1
  17. package/build/src/queries/account/index.js +14 -0
  18. package/build/src/queries/admin/index.d.ts +6 -21
  19. package/build/src/queries/keys.d.ts +1 -0
  20. package/build/src/queries/keys.js +1 -0
  21. package/package.json +12 -11
  22. package/skills/authkit-react-auth/SKILL.md +39 -22
  23. package/build/src/hooks/use_authorized_apps.d.ts +0 -16
  24. package/build/src/hooks/use_authorized_apps.js +0 -15
  25. package/build/src/hooks/use_org_invitations.d.ts +0 -19
  26. package/build/src/hooks/use_org_invitations.js +0 -20
  27. package/build/src/hooks/use_organization.d.ts +0 -23
  28. package/build/src/hooks/use_organization.js +0 -10
  29. package/build/src/hooks/use_organizations.d.ts +0 -18
  30. package/build/src/hooks/use_organizations.js +0 -14
  31. package/build/src/hooks/use_profile.d.ts +0 -13
  32. package/build/src/hooks/use_profile.js +0 -32
  33. package/build/src/hooks/use_sessions.d.ts +0 -16
  34. package/build/src/hooks/use_sessions.js +0 -15
  35. package/build/src/hooks/use_switch_organization.d.ts +0 -7
  36. package/build/src/hooks/use_switch_organization.js +0 -42
@@ -1,32 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
- import { useAuthkitConfig } from '../config.js';
3
- import { useAuth } from '../use_auth.js';
4
- import { jsonRequest } from './use_resource.js';
5
- export function useProfile() {
6
- const config = useAuthkitConfig();
7
- const { user } = useAuth();
8
- const [state, setState] = useState({
9
- data: user,
10
- loading: false,
11
- error: null,
12
- });
13
- const update = useCallback(async (data) => {
14
- setState((s) => ({ ...s, loading: true, error: null }));
15
- try {
16
- const updated = await jsonRequest(config.endpoints.profile, {
17
- method: 'POST',
18
- body: JSON.stringify(data),
19
- csrfToken: config.csrfToken,
20
- });
21
- setState({
22
- data: updated ?? { ...user, ...data },
23
- loading: false,
24
- error: null,
25
- });
26
- }
27
- catch (err) {
28
- setState((s) => ({ ...s, loading: false, error: err }));
29
- }
30
- }, [config.endpoints.profile, config.csrfToken, user]);
31
- return { ...state, actions: { update } };
32
- }
@@ -1,16 +0,0 @@
1
- import { type ResourceState } from './use_resource.js';
2
- export interface AuthSession {
3
- id: string;
4
- device?: string;
5
- ip?: string;
6
- lastSeenAt?: string;
7
- current?: boolean;
8
- [key: string]: unknown;
9
- }
10
- export interface UseSessionsResult extends ResourceState<AuthSession[]> {
11
- actions: {
12
- refetch(): Promise<void>;
13
- revoke(id: string): Promise<void>;
14
- };
15
- }
16
- export declare function useSessions(): UseSessionsResult;
@@ -1,15 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { useAuthkitConfig } from '../config.js';
3
- import { jsonRequest, useResource } from './use_resource.js';
4
- export function useSessions() {
5
- const config = useAuthkitConfig();
6
- const { data, loading, error, refetch } = useResource(config.endpoints.sessions, config.csrfToken);
7
- const revoke = useCallback(async (id) => {
8
- await jsonRequest(`${config.endpoints.sessions}/${encodeURIComponent(id)}/revoke`, {
9
- method: 'POST',
10
- csrfToken: config.csrfToken,
11
- });
12
- await refetch();
13
- }, [config.endpoints.sessions, config.csrfToken, refetch]);
14
- return { data, loading, error, actions: { refetch, revoke } };
15
- }
@@ -1,7 +0,0 @@
1
- export interface UseSwitchOrganizationResult {
2
- loading: boolean;
3
- error: Error | null;
4
- activate(orgId: string): Promise<void>;
5
- deactivate(): Promise<void>;
6
- }
7
- export declare function useSwitchOrganization(): UseSwitchOrganizationResult;
@@ -1,42 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
- import { useAuthkitConfig } from '../config.js';
3
- import { jsonRequest } from './use_resource.js';
4
- export function useSwitchOrganization() {
5
- const config = useAuthkitConfig();
6
- const base = config.endpoints.orgs.replace('/json', '');
7
- const [loading, setLoading] = useState(false);
8
- const [error, setError] = useState(null);
9
- const activate = useCallback(async (orgId) => {
10
- setLoading(true);
11
- setError(null);
12
- try {
13
- await jsonRequest(`${base}/${encodeURIComponent(orgId)}/activate`, {
14
- method: 'POST',
15
- csrfToken: config.csrfToken,
16
- });
17
- }
18
- catch (err) {
19
- setError(err);
20
- }
21
- finally {
22
- setLoading(false);
23
- }
24
- }, [base, config.csrfToken]);
25
- const deactivate = useCallback(async () => {
26
- setLoading(true);
27
- setError(null);
28
- try {
29
- await jsonRequest(`${base}/deactivate`, {
30
- method: 'POST',
31
- csrfToken: config.csrfToken,
32
- });
33
- }
34
- catch (err) {
35
- setError(err);
36
- }
37
- finally {
38
- setLoading(false);
39
- }
40
- }, [base, config.csrfToken]);
41
- return { loading, error, activate, deactivate };
42
- }