@mano8/astro-auth-m8 1.4.1 → 2.0.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/CHANGELOG.md +116 -0
- package/README.md +70 -3
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +3 -1
- package/dist/src/integration.js.map +1 -1
- package/dist/src/runtime/api/apiKeys.d.ts +3 -1
- package/dist/src/runtime/api/apiKeys.d.ts.map +1 -1
- package/dist/src/runtime/api/apiKeys.js +9 -1
- package/dist/src/runtime/api/apiKeys.js.map +1 -1
- package/dist/src/runtime/api/index.d.ts +1 -0
- package/dist/src/runtime/api/index.d.ts.map +1 -1
- package/dist/src/runtime/api/index.js +1 -0
- package/dist/src/runtime/api/index.js.map +1 -1
- package/dist/src/runtime/api/ops.d.ts +2 -1
- package/dist/src/runtime/api/ops.d.ts.map +1 -1
- package/dist/src/runtime/api/ops.js +6 -1
- package/dist/src/runtime/api/ops.js.map +1 -1
- package/dist/src/runtime/api/security.d.ts +8 -0
- package/dist/src/runtime/api/security.d.ts.map +1 -0
- package/dist/src/runtime/api/security.js +23 -0
- package/dist/src/runtime/api/security.js.map +1 -0
- package/dist/src/runtime/api/users.d.ts +2 -2
- package/dist/src/runtime/api/users.d.ts.map +1 -1
- package/dist/src/runtime/api/users.js +2 -2
- package/dist/src/runtime/api/users.js.map +1 -1
- package/dist/src/runtime/authEvents.d.ts +25 -0
- package/dist/src/runtime/authEvents.d.ts.map +1 -0
- package/dist/src/runtime/authEvents.js +26 -0
- package/dist/src/runtime/authEvents.js.map +1 -0
- package/dist/src/runtime/authorization.d.ts +80 -0
- package/dist/src/runtime/authorization.d.ts.map +1 -0
- package/dist/src/runtime/authorization.js +109 -0
- package/dist/src/runtime/authorization.js.map +1 -0
- package/dist/src/runtime/browserAdapter.d.ts +18 -0
- package/dist/src/runtime/browserAdapter.d.ts.map +1 -0
- package/dist/src/runtime/browserAdapter.js +50 -0
- package/dist/src/runtime/browserAdapter.js.map +1 -0
- package/dist/src/runtime/compatibility.d.ts +6 -6
- package/dist/src/runtime/compatibility.d.ts.map +1 -1
- package/dist/src/runtime/compatibility.js +35 -5
- package/dist/src/runtime/compatibility.js.map +1 -1
- package/dist/src/runtime/errors.d.ts +39 -0
- package/dist/src/runtime/errors.d.ts.map +1 -1
- package/dist/src/runtime/errors.js +79 -0
- package/dist/src/runtime/errors.js.map +1 -1
- package/dist/src/runtime/hooks/index.d.ts +1 -0
- package/dist/src/runtime/hooks/index.d.ts.map +1 -1
- package/dist/src/runtime/hooks/index.js +1 -0
- package/dist/src/runtime/hooks/index.js.map +1 -1
- package/dist/src/runtime/hooks/useApiKeys.d.ts +69 -0
- package/dist/src/runtime/hooks/useApiKeys.d.ts.map +1 -1
- package/dist/src/runtime/hooks/useApiKeys.js +38 -1
- package/dist/src/runtime/hooks/useApiKeys.js.map +1 -1
- package/dist/src/runtime/hooks/useSecurity.d.ts +70 -0
- package/dist/src/runtime/hooks/useSecurity.d.ts.map +1 -0
- package/dist/src/runtime/hooks/useSecurity.js +60 -0
- package/dist/src/runtime/hooks/useSecurity.js.map +1 -0
- package/dist/src/runtime/hooks/useUsers.d.ts +4 -15
- package/dist/src/runtime/hooks/useUsers.d.ts.map +1 -1
- package/dist/src/runtime/hooks/useUsers.js +18 -4
- package/dist/src/runtime/hooks/useUsers.js.map +1 -1
- package/dist/src/runtime/queryKeys.d.ts +2 -0
- package/dist/src/runtime/queryKeys.d.ts.map +1 -1
- package/dist/src/runtime/queryKeys.js +3 -1
- package/dist/src/runtime/queryKeys.js.map +1 -1
- package/dist/src/runtime/react/AuthProvider.d.ts.map +1 -1
- package/dist/src/runtime/react/AuthProvider.js +24 -0
- package/dist/src/runtime/react/AuthProvider.js.map +1 -1
- package/dist/src/runtime/react/RequireRole.d.ts.map +1 -1
- package/dist/src/runtime/react/RequireRole.js +3 -2
- package/dist/src/runtime/react/RequireRole.js.map +1 -1
- package/dist/src/runtime/react/index.d.ts +1 -0
- package/dist/src/runtime/react/index.d.ts.map +1 -1
- package/dist/src/runtime/react/index.js +4 -0
- package/dist/src/runtime/react/index.js.map +1 -1
- package/dist/src/runtime/schemas.d.ts +186 -1
- package/dist/src/runtime/schemas.d.ts.map +1 -1
- package/dist/src/runtime/schemas.js +74 -3
- package/dist/src/runtime/schemas.js.map +1 -1
- package/package.json +18 -12
- package/registry/r/account-crud.json +1 -1
- package/registry/r/account-dashboard.json +1 -1
- package/registry/r/admin-users-panel.json +1 -1
- package/registry/r/api-keys-panel.json +1 -1
- package/registry/r/registry.json +6 -0
- package/registry/r/security-panel.json +27 -0
- package/registry/r/sessions-panel.json +1 -1
- package/registry.json +22 -0
|
@@ -6,6 +6,8 @@ export declare function useApiKeys(load?: boolean): {
|
|
|
6
6
|
expires_at: string | null;
|
|
7
7
|
revoked: boolean;
|
|
8
8
|
last_used_at: string | null;
|
|
9
|
+
access_mode: "read_only" | "read_write";
|
|
10
|
+
audiences: string[];
|
|
9
11
|
created_at?: string | undefined;
|
|
10
12
|
updated_at?: string | undefined;
|
|
11
13
|
}[];
|
|
@@ -15,6 +17,8 @@ export declare function useApiKeys(load?: boolean): {
|
|
|
15
17
|
expires_at: string | null;
|
|
16
18
|
revoked: boolean;
|
|
17
19
|
last_used_at: string | null;
|
|
20
|
+
access_mode: "read_only" | "read_write";
|
|
21
|
+
audiences: string[];
|
|
18
22
|
plaintext: string;
|
|
19
23
|
created_at?: string | undefined;
|
|
20
24
|
updated_at?: string | undefined;
|
|
@@ -27,6 +31,8 @@ export declare function useApiKeys(load?: boolean): {
|
|
|
27
31
|
expires_at: string | null;
|
|
28
32
|
revoked: boolean;
|
|
29
33
|
last_used_at: string | null;
|
|
34
|
+
access_mode: "read_only" | "read_write";
|
|
35
|
+
audiences: string[];
|
|
30
36
|
created_at?: string | undefined;
|
|
31
37
|
updated_at?: string | undefined;
|
|
32
38
|
}[]>;
|
|
@@ -36,6 +42,8 @@ export declare function useApiKeys(load?: boolean): {
|
|
|
36
42
|
expires_at: string | null;
|
|
37
43
|
revoked: boolean;
|
|
38
44
|
last_used_at: string | null;
|
|
45
|
+
access_mode: "read_only" | "read_write";
|
|
46
|
+
audiences: string[];
|
|
39
47
|
plaintext: string;
|
|
40
48
|
created_at?: string | undefined;
|
|
41
49
|
updated_at?: string | undefined;
|
|
@@ -49,12 +57,16 @@ export declare function useApiKeys(load?: boolean): {
|
|
|
49
57
|
expires_at: string | null;
|
|
50
58
|
revoked: boolean;
|
|
51
59
|
last_used_at: string | null;
|
|
60
|
+
access_mode: "read_only" | "read_write";
|
|
61
|
+
audiences: string[];
|
|
52
62
|
plaintext: string;
|
|
53
63
|
created_at?: string | undefined;
|
|
54
64
|
updated_at?: string | undefined;
|
|
55
65
|
}, Error, {
|
|
56
66
|
ttl_hours: number;
|
|
67
|
+
access_mode: "read_only" | "read_write";
|
|
57
68
|
name?: string | null | undefined;
|
|
69
|
+
audiences?: string[] | null | undefined;
|
|
58
70
|
}, unknown>;
|
|
59
71
|
revokeMutation: import("@tanstack/react-query").UseMutationResult<{
|
|
60
72
|
message: string;
|
|
@@ -67,8 +79,65 @@ export declare function useApiKeys(load?: boolean): {
|
|
|
67
79
|
expires_at: string | null;
|
|
68
80
|
revoked: boolean;
|
|
69
81
|
last_used_at: string | null;
|
|
82
|
+
access_mode: "read_only" | "read_write";
|
|
83
|
+
audiences: string[];
|
|
70
84
|
created_at?: string | undefined;
|
|
71
85
|
updated_at?: string | undefined;
|
|
72
86
|
}[]>, Error>>;
|
|
73
87
|
};
|
|
88
|
+
export declare function useAdminApiKeys(userId: string, load?: boolean): {
|
|
89
|
+
apiKeys: {
|
|
90
|
+
id: string;
|
|
91
|
+
name: string | null;
|
|
92
|
+
user_id: string;
|
|
93
|
+
revoked: boolean;
|
|
94
|
+
expires_at: string | null;
|
|
95
|
+
last_used_at: string | null;
|
|
96
|
+
created_at: string;
|
|
97
|
+
access_mode: "read_only" | "read_write";
|
|
98
|
+
status: "revoked" | "active" | "expired";
|
|
99
|
+
audiences: string[];
|
|
100
|
+
}[];
|
|
101
|
+
count: number;
|
|
102
|
+
loading: boolean;
|
|
103
|
+
error: Error | null;
|
|
104
|
+
reload: () => Promise<NoInfer<{
|
|
105
|
+
data: {
|
|
106
|
+
id: string;
|
|
107
|
+
name: string | null;
|
|
108
|
+
user_id: string;
|
|
109
|
+
revoked: boolean;
|
|
110
|
+
expires_at: string | null;
|
|
111
|
+
last_used_at: string | null;
|
|
112
|
+
created_at: string;
|
|
113
|
+
access_mode: "read_only" | "read_write";
|
|
114
|
+
status: "revoked" | "active" | "expired";
|
|
115
|
+
audiences: string[];
|
|
116
|
+
}[];
|
|
117
|
+
count: number;
|
|
118
|
+
}> | null>;
|
|
119
|
+
revoke: (keyId: string) => Promise<{
|
|
120
|
+
message: string;
|
|
121
|
+
}>;
|
|
122
|
+
revokeMutation: import("@tanstack/react-query").UseMutationResult<{
|
|
123
|
+
message: string;
|
|
124
|
+
}, Error, string, unknown>;
|
|
125
|
+
isLoading: boolean;
|
|
126
|
+
isFetching: boolean;
|
|
127
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<NoInfer<{
|
|
128
|
+
data: {
|
|
129
|
+
id: string;
|
|
130
|
+
name: string | null;
|
|
131
|
+
user_id: string;
|
|
132
|
+
revoked: boolean;
|
|
133
|
+
expires_at: string | null;
|
|
134
|
+
last_used_at: string | null;
|
|
135
|
+
created_at: string;
|
|
136
|
+
access_mode: "read_only" | "read_write";
|
|
137
|
+
status: "revoked" | "active" | "expired";
|
|
138
|
+
audiences: string[];
|
|
139
|
+
}[];
|
|
140
|
+
count: number;
|
|
141
|
+
}>, Error>>;
|
|
142
|
+
};
|
|
74
143
|
//# sourceMappingURL=useApiKeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useApiKeys.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/useApiKeys.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useApiKeys.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/useApiKeys.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAqB,YAAY,EAA+B,MAAM,eAAe,CAAC;AAElG,wBAAgB,UAAU,CAAC,IAAI,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA6BF,YAAY;;;;;;;;;;;;iBACd,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBvC;AAKD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAmBtB,MAAM;;;;;;;;;;;;;;;;;;;;;;;EAkB1C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
2
2
|
import { useCallback, useState } from "react";
|
|
3
|
-
import { createApiKey, listApiKeys, revokeApiKey } from "../api/apiKeys.js";
|
|
3
|
+
import { adminListUserApiKeys, adminRevokeApiKey, createApiKey, listApiKeys, revokeApiKey } from "../api/apiKeys.js";
|
|
4
4
|
import { refetchOrThrow } from "./queryHelpers.js";
|
|
5
5
|
import { authKeys } from "../queryKeys.js";
|
|
6
6
|
export function useApiKeys(load = true) {
|
|
@@ -48,4 +48,41 @@ export function useApiKeys(load = true) {
|
|
|
48
48
|
refetch: apiKeysQuery.refetch
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
// Superadmin-only surface (AA-13, AA-17): list + revoke another user's keys.
|
|
52
|
+
// Metadata only — never the raw or hashed key — and there is no create/edit
|
|
53
|
+
// path here, unlike the owner-scoped `useApiKeys` above.
|
|
54
|
+
export function useAdminApiKeys(userId, load = true) {
|
|
55
|
+
const queryClient = useQueryClient();
|
|
56
|
+
const adminKeysQuery = useQuery({
|
|
57
|
+
queryKey: authKeys.adminApiKeys(userId),
|
|
58
|
+
queryFn: () => adminListUserApiKeys(userId),
|
|
59
|
+
enabled: load && Boolean(userId),
|
|
60
|
+
staleTime: 30_000
|
|
61
|
+
});
|
|
62
|
+
const revokeMutation = useMutation({
|
|
63
|
+
mutationFn: adminRevokeApiKey,
|
|
64
|
+
onSuccess: async () => {
|
|
65
|
+
await queryClient.invalidateQueries({ queryKey: authKeys.adminApiKeys(userId) });
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const { refetch } = adminKeysQuery;
|
|
69
|
+
const { mutateAsync: revokeApiKeyAsync } = revokeMutation;
|
|
70
|
+
const reload = useCallback(() => refetchOrThrow(refetch, null), [refetch]);
|
|
71
|
+
const revoke = useCallback((keyId) => revokeApiKeyAsync(keyId), [revokeApiKeyAsync]);
|
|
72
|
+
const apiKeys = adminKeysQuery.data?.data ?? [];
|
|
73
|
+
const count = adminKeysQuery.data?.count ?? 0;
|
|
74
|
+
const loading = adminKeysQuery.isLoading || adminKeysQuery.isFetching;
|
|
75
|
+
return {
|
|
76
|
+
apiKeys,
|
|
77
|
+
count,
|
|
78
|
+
loading,
|
|
79
|
+
error: adminKeysQuery.error ?? null,
|
|
80
|
+
reload,
|
|
81
|
+
revoke,
|
|
82
|
+
revokeMutation,
|
|
83
|
+
isLoading: adminKeysQuery.isLoading,
|
|
84
|
+
isFetching: adminKeysQuery.isFetching,
|
|
85
|
+
refetch: adminKeysQuery.refetch
|
|
86
|
+
};
|
|
87
|
+
}
|
|
51
88
|
//# sourceMappingURL=useApiKeys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useApiKeys.js","sourceRoot":"","sources":["../../../../src/runtime/hooks/useApiKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAA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AAE,cAAc,CAAC,UAAU;QACrC,OAAO,EAAE,cAAc,CAAC,OAAO;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { PurgeRequest } from "../schemas.js";
|
|
2
|
+
export declare function useAuditLog(params?: {
|
|
3
|
+
skip?: number;
|
|
4
|
+
limit?: number;
|
|
5
|
+
}, load?: boolean): {
|
|
6
|
+
rows: {
|
|
7
|
+
id: string;
|
|
8
|
+
created_at: string;
|
|
9
|
+
actor_user_id: string;
|
|
10
|
+
actor_role: "superadmin" | "admin" | "writer" | "reader" | "user";
|
|
11
|
+
action: "add" | "edit" | "delete";
|
|
12
|
+
table_name: string;
|
|
13
|
+
row_pk: string;
|
|
14
|
+
target_owner_id?: string | null | undefined;
|
|
15
|
+
}[];
|
|
16
|
+
count: number;
|
|
17
|
+
loading: boolean;
|
|
18
|
+
error: Error | null;
|
|
19
|
+
reload: () => Promise<NoInfer<{
|
|
20
|
+
data: {
|
|
21
|
+
id: string;
|
|
22
|
+
created_at: string;
|
|
23
|
+
actor_user_id: string;
|
|
24
|
+
actor_role: "superadmin" | "admin" | "writer" | "reader" | "user";
|
|
25
|
+
action: "add" | "edit" | "delete";
|
|
26
|
+
table_name: string;
|
|
27
|
+
row_pk: string;
|
|
28
|
+
target_owner_id?: string | null | undefined;
|
|
29
|
+
}[];
|
|
30
|
+
count: number;
|
|
31
|
+
}> | null>;
|
|
32
|
+
isLoading: boolean;
|
|
33
|
+
isFetching: boolean;
|
|
34
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<NoInfer<{
|
|
35
|
+
data: {
|
|
36
|
+
id: string;
|
|
37
|
+
created_at: string;
|
|
38
|
+
actor_user_id: string;
|
|
39
|
+
actor_role: "superadmin" | "admin" | "writer" | "reader" | "user";
|
|
40
|
+
action: "add" | "edit" | "delete";
|
|
41
|
+
table_name: string;
|
|
42
|
+
row_pk: string;
|
|
43
|
+
target_owner_id?: string | null | undefined;
|
|
44
|
+
}[];
|
|
45
|
+
count: number;
|
|
46
|
+
}>, Error>>;
|
|
47
|
+
};
|
|
48
|
+
export declare function useSecurityPurges(): {
|
|
49
|
+
purgeAudit: (window: PurgeRequest["window"]) => Promise<{
|
|
50
|
+
window: "1w" | "1m" | "3m" | "6m" | "1y";
|
|
51
|
+
removed: number;
|
|
52
|
+
}>;
|
|
53
|
+
purgeKeys: (window: PurgeRequest["window"]) => Promise<{
|
|
54
|
+
window: "1w" | "1m" | "3m" | "6m" | "1y";
|
|
55
|
+
removed: number;
|
|
56
|
+
}>;
|
|
57
|
+
purgeAuditLogMutation: import("@tanstack/react-query").UseMutationResult<{
|
|
58
|
+
window: "1w" | "1m" | "3m" | "6m" | "1y";
|
|
59
|
+
removed: number;
|
|
60
|
+
}, Error, {
|
|
61
|
+
window: "1w" | "1m" | "3m" | "6m" | "1y";
|
|
62
|
+
}, unknown>;
|
|
63
|
+
purgeApiKeysMutation: import("@tanstack/react-query").UseMutationResult<{
|
|
64
|
+
window: "1w" | "1m" | "3m" | "6m" | "1y";
|
|
65
|
+
removed: number;
|
|
66
|
+
}, Error, {
|
|
67
|
+
window: "1w" | "1m" | "3m" | "6m" | "1y";
|
|
68
|
+
}, unknown>;
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=useSecurity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSecurity.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/useSecurity.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAA+B,YAAY,EAAE,MAAM,eAAe,CAAC;AAK/E,wBAAgB,WAAW,CAAC,MAAM,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,EAAE,IAAI,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBtF;AAQD,wBAAgB,iBAAiB;yBAgBS,YAAY,CAAC,QAAQ,CAAC;;;;wBACvB,YAAY,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;;;EAQ9D"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { getAuditLog, purgeApiKeys, purgeAuditLog } from "../api/security.js";
|
|
4
|
+
import { refetchOrThrow } from "./queryHelpers.js";
|
|
5
|
+
import { authKeys } from "../queryKeys.js";
|
|
6
|
+
// Admin-tier read (AA-14): gate with `hasMinimumRole(role, "admin")`, not the
|
|
7
|
+
// superuser predicate — the own-rows/all-rows split is decided server-side
|
|
8
|
+
// from the authenticated principal and is never sent by this client.
|
|
9
|
+
export function useAuditLog(params = {}, load = true) {
|
|
10
|
+
const auditLogQuery = useQuery({
|
|
11
|
+
queryKey: authKeys.auditLog(params),
|
|
12
|
+
queryFn: () => getAuditLog(params),
|
|
13
|
+
enabled: load,
|
|
14
|
+
staleTime: 30_000
|
|
15
|
+
});
|
|
16
|
+
const { refetch } = auditLogQuery;
|
|
17
|
+
const reload = useCallback(() => refetchOrThrow(refetch, null), [refetch]);
|
|
18
|
+
const rows = auditLogQuery.data?.data ?? [];
|
|
19
|
+
const count = auditLogQuery.data?.count ?? 0;
|
|
20
|
+
const loading = auditLogQuery.isLoading || auditLogQuery.isFetching;
|
|
21
|
+
return {
|
|
22
|
+
rows,
|
|
23
|
+
count,
|
|
24
|
+
loading,
|
|
25
|
+
error: auditLogQuery.error ?? null,
|
|
26
|
+
reload,
|
|
27
|
+
isLoading: auditLogQuery.isLoading,
|
|
28
|
+
isFetching: auditLogQuery.isFetching,
|
|
29
|
+
refetch: auditLogQuery.refetch
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Superadmin-only maintenance actions (AA-18, AA-19): both purges are
|
|
33
|
+
// idempotent-unsafe, rate limited (429), and fail-closed on 503 — the caller
|
|
34
|
+
// must treat a 503 outcome as unknown, never retry it automatically, and
|
|
35
|
+
// surface a 400 retention-floor rejection verbatim. This hook performs no
|
|
36
|
+
// such interpretation itself; it only invalidates the affected list on a
|
|
37
|
+
// confirmed success.
|
|
38
|
+
export function useSecurityPurges() {
|
|
39
|
+
const queryClient = useQueryClient();
|
|
40
|
+
const purgeAuditLogMutation = useMutation({
|
|
41
|
+
mutationFn: (body) => purgeAuditLog(body),
|
|
42
|
+
onSuccess: async () => {
|
|
43
|
+
await queryClient.invalidateQueries({ queryKey: authKeys.auditLog() });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const purgeApiKeysMutation = useMutation({
|
|
47
|
+
mutationFn: (body) => purgeApiKeys(body)
|
|
48
|
+
});
|
|
49
|
+
const { mutateAsync: purgeAuditLogAsync } = purgeAuditLogMutation;
|
|
50
|
+
const { mutateAsync: purgeApiKeysAsync } = purgeApiKeysMutation;
|
|
51
|
+
const purgeAudit = useCallback((window) => purgeAuditLogAsync({ window }), [purgeAuditLogAsync]);
|
|
52
|
+
const purgeKeys = useCallback((window) => purgeApiKeysAsync({ window }), [purgeApiKeysAsync]);
|
|
53
|
+
return {
|
|
54
|
+
purgeAudit,
|
|
55
|
+
purgeKeys,
|
|
56
|
+
purgeAuditLogMutation,
|
|
57
|
+
purgeApiKeysMutation
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=useSecurity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSecurity.js","sourceRoot":"","sources":["../../../../src/runtime/hooks/useSecurity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,m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xC,UAAU,EAAE,CAAC,IAAkB,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;QACvD,SAAS,EAAE,KAAK,IAAI,EAAE;YACpB,MAAM,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACzE,CAAC;KACF,CAAC,CAAC;IACH,MAAM,oBAAoB,GAAG,WAAW,CAAC;QACvC,UAAU,EAAE,CAAC,IAAkB,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC;KACvD,CAAC,CAAC;IAEH,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,qBAAqB,CAAC;IAClE,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,oBAAoB,CAAC;IAEhE,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,MAA8B,EAAE,EAAE,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACzH,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,MAA8B,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAEtH,OAAO;QACL,UAAU;QACV,SAAS;QACT,qBAAqB;QACrB,oBAAoB;KACrB,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UserCreate, UserRegister, UserUpdate } from "../schemas.js";
|
|
1
|
+
import type { UserAuthorizationUpdate, UserCreate, UserRegister, UserUpdate } from "../schemas.js";
|
|
2
2
|
export declare function useUsers(load?: boolean): {
|
|
3
3
|
users: {
|
|
4
4
|
data: {
|
|
@@ -73,19 +73,7 @@ export declare function useUsers(load?: boolean): {
|
|
|
73
73
|
created_at?: string | undefined;
|
|
74
74
|
updated_at?: string | undefined;
|
|
75
75
|
}>;
|
|
76
|
-
update: (id: string, body: UserUpdate) => Promise<
|
|
77
|
-
id: string;
|
|
78
|
-
provider: "password" | "google";
|
|
79
|
-
email: string;
|
|
80
|
-
full_name: string | null;
|
|
81
|
-
avatar: string | null;
|
|
82
|
-
is_active: boolean;
|
|
83
|
-
email_verified: boolean;
|
|
84
|
-
is_superuser: boolean;
|
|
85
|
-
role: "superadmin" | "admin" | "writer" | "reader" | "user";
|
|
86
|
-
created_at?: string | undefined;
|
|
87
|
-
updated_at?: string | undefined;
|
|
88
|
-
}>;
|
|
76
|
+
update: (id: string, body: UserUpdate) => Promise<UserAuthorizationUpdate>;
|
|
89
77
|
remove: (id: string) => Promise<{
|
|
90
78
|
message: string;
|
|
91
79
|
}>;
|
|
@@ -108,7 +96,6 @@ export declare function useUsers(load?: boolean): {
|
|
|
108
96
|
avatar?: string | null | undefined;
|
|
109
97
|
is_active?: boolean | undefined;
|
|
110
98
|
email_verified?: boolean | undefined;
|
|
111
|
-
is_superuser?: boolean | undefined;
|
|
112
99
|
role?: "superadmin" | "admin" | "writer" | "reader" | "user" | undefined;
|
|
113
100
|
password?: string | null | undefined;
|
|
114
101
|
oauth_user_id?: string | null | undefined;
|
|
@@ -140,6 +127,8 @@ export declare function useUsers(load?: boolean): {
|
|
|
140
127
|
email_verified: boolean;
|
|
141
128
|
is_superuser: boolean;
|
|
142
129
|
role: "superadmin" | "admin" | "writer" | "reader" | "user";
|
|
130
|
+
auth_generation: number;
|
|
131
|
+
revocation_enqueued: boolean;
|
|
143
132
|
created_at?: string | undefined;
|
|
144
133
|
updated_at?: string | undefined;
|
|
145
134
|
}, Error, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUsers.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/useUsers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUsers.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/useUsers.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAe,MAAM,eAAe,CAAC;AAEhH,wBAAgB,QAAQ,CAAC,IAAI,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAuEA,UAAU;;;;;;;;;;;;;mBACV,YAAY;;;;;;;;;;;;;cACjB,MAAM;;;;;;;;;;;;;iBAKH,MAAM,QAAQ,UAAU,KAAG,OAAO,CAAC,uBAAuB,CAAC;iBAC3D,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAvDH,MAAM;cAAQ,UAAU;;;;;;;;;;;;;;;;;;;;;;;EA8E5D"}
|
|
@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
import { createUser, deleteUser, getUser, listUsers, signupUser, updateUser } from "../api/users.js";
|
|
4
4
|
import { refetchOrThrow } from "./queryHelpers.js";
|
|
5
|
+
import { emitAuthRevocation } from "../authEvents.js";
|
|
5
6
|
import { authKeys } from "../queryKeys.js";
|
|
6
7
|
export function useUsers(load = true) {
|
|
7
8
|
const queryClient = useQueryClient();
|
|
@@ -30,10 +31,23 @@ export function useUsers(load = true) {
|
|
|
30
31
|
onSuccess: async (updatedUser, variables) => {
|
|
31
32
|
queryClient.setQueryData(authKeys.user(variables.id), updatedUser);
|
|
32
33
|
queryClient.setQueryData(authKeys.user(updatedUser.id), updatedUser);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const staleKeys = [authKeys.users(), authKeys.user(variables.id)];
|
|
35
|
+
// AA-11: `revocation_enqueued` reports that the target's sessions were
|
|
36
|
+
// revoked and an authorization-generation bump is propagating, so every
|
|
37
|
+
// cached view of that principal's privileges is stale - dropping it is
|
|
38
|
+
// what stops a demoted user rendering privileged UI from cache. The
|
|
39
|
+
// owner-scoped profile/session/key caches are invalidated too: this layer
|
|
40
|
+
// cannot tell whether the target is the signed-in principal, and a
|
|
41
|
+
// redundant refetch is strictly safer than a stale privileged view.
|
|
42
|
+
if (updatedUser.revocation_enqueued) {
|
|
43
|
+
staleKeys.push(authKeys.profile(), authKeys.sessions(), authKeys.apiKeys(), authKeys.adminApiKeys(variables.id));
|
|
44
|
+
}
|
|
45
|
+
await Promise.all(staleKeys.map((queryKey) => queryClient.invalidateQueries({ queryKey })));
|
|
46
|
+
// The provider holds the signed-in user in memory, outside this cache;
|
|
47
|
+
// notify it so it re-reads the profile instead of waiting for the next
|
|
48
|
+
// incidental `getProfile()`. It ignores every other user id.
|
|
49
|
+
if (updatedUser.revocation_enqueued)
|
|
50
|
+
emitAuthRevocation(variables.id);
|
|
37
51
|
}
|
|
38
52
|
});
|
|
39
53
|
const removeMutation = useMutation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUsers.js","sourceRoot":"","sources":["../../../../src/runtime/hooks/useUsers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"useUsers.js","sourceRoot":"","sources":["../../../../src/runtime/hooks/useUsers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAiB,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,MAAM,UAAU,QAAQ,CAAC,IAAI,GAAG,IAAI;IAClC,MAAM,WAAW,GAAG,cAAc,EAAE,CAA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AC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IACjJ,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEnF,MAAM,KAAK,GAAuB,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC;IAC1D,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,IAAI,UAAU,CAAC,UAAU,CAAC;IAE9D,OAAO;QACL,KAAK;QACL,OAAO;QACP,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,IAAI;QAC/B,MAAM;QACN,MAAM;QACN,MAAM;QACN,GAAG;QACH,MAAM;QACN,MAAM;QACN,cAAc;QACd,cAAc;QACd,cAAc;QACd,cAAc;QACd,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,OAAO,EAAE,UAAU,CAAC,OAAO;KAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -6,5 +6,7 @@ export declare const authKeys: {
|
|
|
6
6
|
readonly user: (id: string) => readonly ["auth", "users", string];
|
|
7
7
|
readonly sessions: () => readonly ["auth", "sessions"];
|
|
8
8
|
readonly apiKeys: () => readonly ["auth", "apiKeys"];
|
|
9
|
+
readonly adminApiKeys: (userId: string) => readonly ["auth", "adminApiKeys", string];
|
|
10
|
+
readonly auditLog: (params?: Record<string, unknown>) => readonly ["auth", "auditLog", Record<string, unknown>];
|
|
9
11
|
};
|
|
10
12
|
//# sourceMappingURL=queryKeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryKeys.d.ts","sourceRoot":"","sources":["../../../src/runtime/queryKeys.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;iCAGA,IAAI,GAAG,QAAQ;8BACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;wBAC7B,MAAM;;;
|
|
1
|
+
{"version":3,"file":"queryKeys.d.ts","sourceRoot":"","sources":["../../../src/runtime/queryKeys.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;iCAGA,IAAI,GAAG,QAAQ;8BACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;wBAC7B,MAAM;;;oCAGM,MAAM;iCACT,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CACnC,CAAC"}
|
|
@@ -6,6 +6,8 @@ export const authKeys = {
|
|
|
6
6
|
users: (params) => [...authKeyRoot, "users", params ?? {}],
|
|
7
7
|
user: (id) => [...authKeyRoot, "users", id],
|
|
8
8
|
sessions: () => [...authKeyRoot, "sessions"],
|
|
9
|
-
apiKeys: () => [...authKeyRoot, "apiKeys"]
|
|
9
|
+
apiKeys: () => [...authKeyRoot, "apiKeys"],
|
|
10
|
+
adminApiKeys: (userId) => [...authKeyRoot, "adminApiKeys", userId],
|
|
11
|
+
auditLog: (params) => [...authKeyRoot, "auditLog", params ?? {}]
|
|
10
12
|
};
|
|
11
13
|
//# sourceMappingURL=queryKeys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryKeys.js","sourceRoot":"","sources":["../../../src/runtime/queryKeys.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,CAAC,MAAM,CAAU,CAAC;AAEtC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,GAAG,EAAE,GAAG,EAAE,CAAC,WAAW;IACtB,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,WAAW,EAAE,SAAS,CAAU;IACnD,SAAS,EAAE,CAAC,QAAyB,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,WAAW,EAAE,WAAW,EAAE,KAAK,CAAU;IAC3F,KAAK,EAAE,CAAC,MAAgC,EAAE,EAAE,CAAC,CAAC,GAAG,WAAW,EAAE,OAAO,EAAE,MAAM,IAAI,EAAE,CAAU;IAC7F,IAAI,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,CA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sources":["../../../../src/runtime/react/AuthProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7G,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/AuthProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7G,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACnE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,EAAE,MAAM,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAC1C,CAAC;AA0CF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAgB,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,+BAwGrJ;AAED,wBAAgB,OAAO,IAAI,gBAAgB,CAI1C"}
|
|
@@ -3,6 +3,7 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useState }
|
|
|
3
3
|
import { configureAuth } from "../config.js";
|
|
4
4
|
import { login as apiLogin, logout as apiLogout, refreshToken } from "../api/auth.js";
|
|
5
5
|
import { getProfile } from "../api/profile.js";
|
|
6
|
+
import { AUTH_REVOCATION_EVENT } from "../authEvents.js";
|
|
6
7
|
import { AuthQueryProvider } from "./AuthQueryProvider.js";
|
|
7
8
|
const AuthContext = createContext(null);
|
|
8
9
|
const AUTH_SESSION_EVENT = "fa-auth-m8:session";
|
|
@@ -10,6 +11,7 @@ const BOOTSTRAP_FAILURE_COOLDOWN_MS = 30_000;
|
|
|
10
11
|
let bootstrapSessionPromise = null;
|
|
11
12
|
let bootstrapFailureUntil = 0;
|
|
12
13
|
function emitAuthSession(user) {
|
|
14
|
+
/* v8 ignore next -- SSR guard: only reachable if this module runs outside a browser, which the jsdom test environment cannot simulate without corrupting the DOM globals it also depends on (see client.ts's analogous guard, tested via a separate non-jsdom file instead) */
|
|
13
15
|
if (typeof window === "undefined")
|
|
14
16
|
return;
|
|
15
17
|
window.dispatchEvent(new CustomEvent(AUTH_SESSION_EVENT, { detail: { user } }));
|
|
@@ -93,6 +95,28 @@ export function AuthProvider({ children, config, bootstrap = true }) {
|
|
|
93
95
|
cancelled = true;
|
|
94
96
|
};
|
|
95
97
|
}, [bootstrap, reload]);
|
|
98
|
+
// AA-11: `revocation_enqueued: true` means the backend has already revoked the
|
|
99
|
+
// target principal's sessions and is propagating an authorization-generation
|
|
100
|
+
// bump. When that principal is the signed-in one, the claims held here are
|
|
101
|
+
// stale the moment the response lands, so re-read the profile now instead of
|
|
102
|
+
// waiting for whichever later call would incidentally refresh it. `loading`
|
|
103
|
+
// is raised for the duration so `RequireRole`/`RequireAuth` fall back rather
|
|
104
|
+
// than keep rendering privileged UI from the superseded claims.
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const currentUserId = user?.id;
|
|
107
|
+
if (!currentUserId)
|
|
108
|
+
return;
|
|
109
|
+
const onRevocation = (event) => {
|
|
110
|
+
if (event.detail?.userId !== currentUserId)
|
|
111
|
+
return;
|
|
112
|
+
setLoading(true);
|
|
113
|
+
void reload().finally(() => setLoading(false));
|
|
114
|
+
};
|
|
115
|
+
window.addEventListener(AUTH_REVOCATION_EVENT, onRevocation);
|
|
116
|
+
return () => {
|
|
117
|
+
window.removeEventListener(AUTH_REVOCATION_EVENT, onRevocation);
|
|
118
|
+
};
|
|
119
|
+
}, [reload, user?.id]);
|
|
96
120
|
const login = useCallback(async (username, password) => {
|
|
97
121
|
await apiLogin(username, password);
|
|
98
122
|
const profile = await getProfile();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.js","sourceRoot":"","sources":["../../../../src/runtime/react/AuthProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAC7G,OAAO,EAAE,aAAa,EAA0B,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,IAAI,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","sourceRoot":"","sources":["../../../../src/runtime/react/AuthProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAC7G,OAAO,EAAE,aAAa,EAA0B,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,IAAI,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAA6B,MAAM,kBAAkB,CAAC;AAEpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAW3D,MAAM,WAAW,GAAG,aAAa,CAA0B,IAAI,CAAC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xC,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC1E,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequireRole.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/RequireRole.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"RequireRole.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/RequireRole.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,wBAAgB,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAiB,EAAE,QAAe,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,aAM1K"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useAuth } from "./AuthProvider.js";
|
|
2
|
+
import { hasMinimumRole, hasSuperuserPrivileges } from "../authorization.js";
|
|
2
3
|
export function RequireRole({ children, roles, superuser = false, fallback = null }) {
|
|
3
4
|
const { user, loading } = useAuth();
|
|
4
5
|
if (loading || !user)
|
|
5
6
|
return fallback;
|
|
6
|
-
if (superuser && user.is_superuser)
|
|
7
|
+
if (superuser && hasSuperuserPrivileges(user.role, user.is_superuser))
|
|
7
8
|
return children;
|
|
8
|
-
if (roles?.
|
|
9
|
+
if (roles?.some((requiredRole) => hasMinimumRole(user.role, requiredRole)))
|
|
9
10
|
return children;
|
|
10
11
|
return fallback;
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequireRole.js","sourceRoot":"","sources":["../../../../src/runtime/react/RequireRole.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"RequireRole.js","sourceRoot":"","sources":["../../../../src/runtime/react/RequireRole.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,GAAG,KAAK,EAAE,QAAQ,GAAG,IAAI,EAA0F;IACzK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;IACpC,IAAI,OAAO,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC;IACtC,IAAI,SAAS,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvF,IAAI,KAAK,EAAE,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC5F,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxG,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Announced by the hook layer on a `revocation_enqueued` response and consumed
|
|
2
|
+
// by `AuthProvider`; re-exported here so a consumer with its own mutation layer
|
|
3
|
+
// can announce one through an existing public subpath.
|
|
4
|
+
export { AUTH_REVOCATION_EVENT, emitAuthRevocation } from "../authEvents.js";
|
|
1
5
|
export * from "./AuthQueryProvider.js";
|
|
2
6
|
export * from "./AuthProvider.js";
|
|
3
7
|
export * from "./RequireAuth.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/react/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gFAAgF;AAChF,uDAAuD;AACvD,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAA6B,MAAM,kBAAkB,CAAC;AACxG,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|