@object-ui/auth 17.6.0 → 18.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 +598 -0
- package/README.md +124 -19
- package/dist/ActiveOrganizationStorage.d.ts +32 -1
- package/dist/ActiveOrganizationStorage.d.ts.map +1 -1
- package/dist/ActiveOrganizationStorage.js +72 -3
- package/dist/AuthContext.d.ts +10 -3
- package/dist/AuthContext.d.ts.map +1 -1
- package/dist/AuthProvider.d.ts.map +1 -1
- package/dist/AuthProvider.js +101 -18
- package/dist/LoginForm.d.ts +35 -4
- package/dist/LoginForm.d.ts.map +1 -1
- package/dist/LoginForm.js +16 -4
- package/dist/RegisterForm.d.ts +21 -2
- package/dist/RegisterForm.d.ts.map +1 -1
- package/dist/RegisterForm.js +3 -4
- package/dist/SocialSignInButtons.d.ts +15 -2
- package/dist/SocialSignInButtons.d.ts.map +1 -1
- package/dist/SocialSignInButtons.js +3 -3
- package/dist/UserMenu.d.ts +1 -1
- package/dist/UserMenu.js +1 -1
- package/dist/auth-gate-events.d.ts +6 -4
- package/dist/auth-gate-events.d.ts.map +1 -1
- package/dist/auth-gate-events.js +11 -1
- package/dist/authStyles.d.ts +8 -3
- package/dist/authStyles.d.ts.map +1 -1
- package/dist/authStyles.js +8 -3
- package/dist/createAuthClient.d.ts +15 -1
- package/dist/createAuthClient.d.ts.map +1 -1
- package/dist/createAuthClient.js +54 -1
- package/dist/createAuthenticatedFetch.d.ts +5 -4
- package/dist/createAuthenticatedFetch.d.ts.map +1 -1
- package/dist/createAuthenticatedFetch.js +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/types.d.ts +53 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/useWorkspaceAdminStatus.d.ts +76 -27
- package/dist/useWorkspaceAdminStatus.d.ts.map +1 -1
- package/dist/useWorkspaceAdminStatus.js +146 -40
- package/package.json +6 -7
|
@@ -6,6 +6,20 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import { useAuth } from './useAuth.js';
|
|
9
|
+
/**
|
|
10
|
+
* The vocabulary of the two SCALAR legs — a membership row's `role` (leg 1)
|
|
11
|
+
* and the stored `user.role` (leg 2).
|
|
12
|
+
*
|
|
13
|
+
* Both are single values written by a path the tenant does not control: leg 1
|
|
14
|
+
* is better-auth's `sys_member.role`, capped at the issuer's own grade on
|
|
15
|
+
* every issuance path; leg 2 is `sys_user.role`, which framework ADR-0092 D2's
|
|
16
|
+
* identity write guard refuses under a user context. A name found in either is
|
|
17
|
+
* therefore evidence.
|
|
18
|
+
*
|
|
19
|
+
* ⛔ This set is NOT the vocabulary for `user.positions[]` — see
|
|
20
|
+
* {@link ADMIN_POSITION_NAMES} for the narrower one that leg 3b uses, and the
|
|
21
|
+
* hook's docblock for why the two had to be separated (objectui#8291).
|
|
22
|
+
*/
|
|
9
23
|
const ADMIN_ROLES = new Set([
|
|
10
24
|
'owner',
|
|
11
25
|
'admin',
|
|
@@ -13,51 +27,138 @@ const ADMIN_ROLES = new Set([
|
|
|
13
27
|
'superadmin',
|
|
14
28
|
'platform_admin',
|
|
15
29
|
'system_admin',
|
|
16
|
-
// ADR-0068 canonical names
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
30
|
+
// ADR-0068 canonical names. `mapMembershipRole` normalizes raw better-auth
|
|
31
|
+
// owner/admin to org_owner/org_admin before they reach a session payload, so
|
|
32
|
+
// a membership role can arrive here in either spelling depending on which
|
|
33
|
+
// surface produced it. Accept both so admin detection survives the removal
|
|
34
|
+
// of the `user.role = 'admin'` overwrite footgun.
|
|
20
35
|
'org_owner',
|
|
21
36
|
'org_admin',
|
|
22
37
|
]);
|
|
23
38
|
/**
|
|
24
|
-
*
|
|
25
|
-
* `user.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
39
|
+
* The vocabulary of leg 3b — the only names honoured when found in
|
|
40
|
+
* `user.positions[]`.
|
|
41
|
+
*
|
|
42
|
+
* Deliberately NOT {@link ADMIN_ROLES}. `positions[]` is a tenant-WRITABLE
|
|
43
|
+
* array (see the hook's docblock), so the question for each name is not "does
|
|
44
|
+
* it sound like an admin" but "does a trusted server derivation ever put it
|
|
45
|
+
* here". Decided name by name in objectui#8291:
|
|
46
|
+
*
|
|
47
|
+
* - `org_owner`, `org_admin` — KEPT. `resolveUserAuthzGrants` emits exactly
|
|
48
|
+
* these from the ACTIVE organization's `sys_member.role` through
|
|
49
|
+
* `mapMembershipRole`, so a hit is usually the real membership row arriving
|
|
50
|
+
* ahead of leg 1. A `sys_user_position` row CAN also spell them, but that
|
|
51
|
+
* row is written by a caller who already holds tenant-administration
|
|
52
|
+
* authority over the same organization (framework `DelegatedAdminGate`), so
|
|
53
|
+
* what they mint is a second spelling of an authority they have — not a
|
|
54
|
+
* crossing of any boundary. This is also the framework's own line: its
|
|
55
|
+
* four-site sweep left every TENANT_ADMIN arm untouched and moved only the
|
|
56
|
+
* platform ones.
|
|
57
|
+
* - `platform_admin` — DROPPED, and replaced by leg 3a. It is the name a
|
|
58
|
+
* tenant can mint to claim authority it does not have, and the array cannot
|
|
59
|
+
* tell a minted one from a genuine one: `resolveUserAuthzGrants` pushes the
|
|
60
|
+
* built-in name only when it is not already present, so both cases produce
|
|
61
|
+
* a byte-identical array.
|
|
62
|
+
* - `owner`, `admin`, `super_admin`, `superadmin`, `system_admin` — DROPPED.
|
|
63
|
+
* No server derivation emits any of them into `positions[]` at all: the
|
|
64
|
+
* membership leg normalizes `owner`/`admin` to `org_*` first, and the other
|
|
65
|
+
* three are not built-in identity names in any framework vocabulary. A hit
|
|
66
|
+
* on one could therefore ONLY be a `sys_user_position` row — all exposure,
|
|
67
|
+
* no signal. They stay in {@link ADMIN_ROLES}, where they are the raw
|
|
68
|
+
* scalars legs 1 and 2 legitimately read.
|
|
69
|
+
*/
|
|
70
|
+
const ADMIN_POSITION_NAMES = new Set([
|
|
71
|
+
'org_owner',
|
|
72
|
+
'org_admin',
|
|
73
|
+
]);
|
|
74
|
+
/**
|
|
75
|
+
* One name from either SCALAR source — a membership role or the stored
|
|
76
|
+
* `user.role` scalar. The two draw on one vocabulary by design (ADR-0068 D2
|
|
77
|
+
* maps a membership `owner`/`admin` onto the canonical `org_owner`/`org_admin`
|
|
78
|
+
* that {@link ADMIN_ROLES} also carries), so one predicate serves both.
|
|
29
79
|
*/
|
|
30
80
|
function isAdminRole(role) {
|
|
31
81
|
return typeof role === 'string' && ADMIN_ROLES.has(role.toLowerCase());
|
|
32
82
|
}
|
|
83
|
+
/** One entry of `user.positions[]`, judged against the narrower vocabulary. */
|
|
84
|
+
function isAdminPosition(position) {
|
|
85
|
+
return typeof position === 'string' && ADMIN_POSITION_NAMES.has(position.toLowerCase());
|
|
86
|
+
}
|
|
33
87
|
/**
|
|
34
88
|
* Whether the current user has owner/admin privileges, and whether that answer
|
|
35
89
|
* has finished resolving.
|
|
36
90
|
*
|
|
37
91
|
* Sources considered (any one is sufficient):
|
|
38
|
-
* -
|
|
39
|
-
* -
|
|
40
|
-
* that still store an admin role on the user row.
|
|
41
|
-
* - `user.
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
92
|
+
* - LEG 1 — the active organization member row (multi-tenant mode).
|
|
93
|
+
* - LEG 2 — the top-level `user.role` scalar from the session: legacy
|
|
94
|
+
* deployments that still store an admin role on the user row.
|
|
95
|
+
* - LEG 3a — `user.isPlatformAdmin` from the session: the server's ADR-0095
|
|
96
|
+
* posture RUNG, and the ONLY leg that sees a platform administrator whose
|
|
97
|
+
* adminship comes from the `admin_full_access` permission set. On a
|
|
98
|
+
* single-tenant deployment there is no member row to read (leg 1) and the
|
|
99
|
+
* server deliberately no longer overwrites `user.role` (leg 2), so this
|
|
100
|
+
* flag is the whole signal for that viewer. Measured on a live protocol-17
|
|
101
|
+
* server in objectui#5389 — the captured payload there carries
|
|
102
|
+
* `isPlatformAdmin: true` — and pinned by
|
|
49
103
|
* `__tests__/workspaceAdminPositions-5389.test.tsx`.
|
|
104
|
+
* - LEG 3b — `user.positions[]` from the session, judged against
|
|
105
|
+
* {@link ADMIN_POSITION_NAMES} rather than {@link ADMIN_ROLES}: the
|
|
106
|
+
* canonical TENANT-scoped identity names the server derives from the active
|
|
107
|
+
* organization's membership row (ADR-0068 D1/D2, renamed from `roles` by
|
|
108
|
+
* ADR-0090 D3). This is what lets a tenant administrator resolve on the
|
|
109
|
+
* first frame instead of waiting for leg 1 (see the objectui#5619 section
|
|
110
|
+
* below).
|
|
111
|
+
*
|
|
112
|
+
* ## Why 3a and 3b are two legs and not one (objectui#8291)
|
|
113
|
+
*
|
|
114
|
+
* This docblock used to argue the opposite, and a future reader who finds that
|
|
115
|
+
* argument standing will re-introduce the defect it now describes. It said:
|
|
116
|
+
* do not read `user.isPlatformAdmin` alongside `positions`, because the server
|
|
117
|
+
* computes the flag as `'platform_admin' in positions` from the same
|
|
118
|
+
* expression, so reading both would be two spellings for one fact with no way
|
|
119
|
+
* to disagree usefully and every way to drift.
|
|
120
|
+
*
|
|
121
|
+
* **That was true and it is now false.** Framework objectstack#15948 (a
|
|
122
|
+
* declared BREAKING change) redefined what `positions[]` IS. It used to be the
|
|
123
|
+
* `sys_user.role` scalar split on commas; it is now built by
|
|
124
|
+
* `resolveUserAuthzGrants` and carries ADR-0057 D4 `sys_user_position`
|
|
125
|
+
* assignments. That table is `apiEnabled` and its `position` values are
|
|
126
|
+
* unconstrained, so a caller holding tenant-administration authority can mint
|
|
127
|
+
* a row spelling `platform_admin` for one of their own users — and the name
|
|
128
|
+
* lands on `positions[]` verbatim.
|
|
129
|
+
*
|
|
130
|
+
* The two therefore no longer say one thing:
|
|
131
|
+
*
|
|
132
|
+
* - `isPlatformAdmin` is `grants.posture === 'PLATFORM_ADMIN'` — derived from
|
|
133
|
+
* an UNSCOPED `admin_full_access` grant (or a verified email on the
|
|
134
|
+
* deployment's declared administrator list) and from nothing else. It is
|
|
135
|
+
* byte-for-byte what the server's own `hasPlatformAdminStanding` returns.
|
|
136
|
+
* - `positions[]` is the security AXIS, which is a wider thing: it is the set
|
|
137
|
+
* of names a request resolves to, including names a tenant wrote.
|
|
138
|
+
*
|
|
139
|
+
* They can now disagree, and when they do **the rung is right** — enforcement
|
|
140
|
+
* agrees with the rung, so the array's extra name buys nothing except a
|
|
141
|
+
* Console that paints platform-administrator surfaces at a principal every
|
|
142
|
+
* underlying call refuses. `resolve-authz-context.ts` states the rule at
|
|
143
|
+
* `hasPlatformAdminStanding`: read the RUNG, never
|
|
144
|
+
* `positions.includes('platform_admin')`. The framework moved four server-side
|
|
145
|
+
* sites onto it (`plugin-sharing`, `plugin-approvals`, `plugin-security`,
|
|
146
|
+
* `runtime`); this hook is the same read on the client side of the wire.
|
|
147
|
+
*
|
|
148
|
+
* ⛔ So: never put `platform_admin` back into {@link ADMIN_POSITION_NAMES},
|
|
149
|
+
* and never widen leg 3b back to {@link ADMIN_ROLES}. The name is not the
|
|
150
|
+
* authority. Every server that publishes `positions` publishes
|
|
151
|
+
* `isPlatformAdmin` beside it — `customSession` returns them in one object
|
|
152
|
+
* literal — so nothing is lost by reading the narrow one.
|
|
50
153
|
*
|
|
51
|
-
* `positions`
|
|
52
|
-
* alongside the retired `roles` (ADR-0090 D3 renamed
|
|
53
|
-
* window and bans resurrecting the old name as a
|
|
54
|
-
*
|
|
55
|
-
* server as `'platform_admin' in positions` from the same expression, so
|
|
56
|
-
* reading both would be two spellings for one fact with no way to disagree
|
|
57
|
-
* usefully and every way to drift.
|
|
154
|
+
* `positions` also remains the ONE published spelling of the array itself. It
|
|
155
|
+
* is deliberately not read alongside the retired `roles` (ADR-0090 D3 renamed
|
|
156
|
+
* with no deprecation window and bans resurrecting the old name as a
|
|
157
|
+
* fallback).
|
|
58
158
|
*
|
|
59
|
-
* In preview-mode / no-auth-enabled mode the provider seeds an admin user
|
|
60
|
-
* so this returns `isAdmin: true` for
|
|
159
|
+
* In preview-mode / no-auth-enabled mode the provider seeds an admin user
|
|
160
|
+
* (`role: 'admin'`, which leg 2 reads), so this returns `isAdmin: true` for
|
|
161
|
+
* dev/demo setups.
|
|
61
162
|
*
|
|
62
163
|
* ## Why this returns a pair and not a boolean (objectui#5619)
|
|
63
164
|
*
|
|
@@ -73,30 +174,35 @@ function isAdminRole(role) {
|
|
|
73
174
|
* console chrome dropped and re-added a nav entry, and `AppContent` fired a
|
|
74
175
|
* `<Navigate to="/home" replace>` that the later flip cannot undo.
|
|
75
176
|
*
|
|
76
|
-
* Legs 2 and
|
|
177
|
+
* Legs 2 and 3b DO cover that viewer whenever the session was minted with an
|
|
77
178
|
* active organization stamped on it — framework `auth-manager.ts` reads
|
|
78
179
|
* `session.activeOrganizationId` and, when it is set, maps the member row into
|
|
79
|
-
* `positions[]` as `org_owner`/`org_admin`.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
180
|
+
* `positions[]` as `org_owner`/`org_admin`. Those two names are exactly why
|
|
181
|
+
* objectui#8291 kept leg 3b alive rather than deleting the array read
|
|
182
|
+
* outright. The window is therefore not "every tenant admin" as first
|
|
183
|
+
* reported, but "every session that reaches the console without that stamp",
|
|
184
|
+
* which is exactly the path `refreshOrganizations`' ADR-0081 repair exists to
|
|
185
|
+
* serve.
|
|
83
186
|
*
|
|
84
187
|
* `isResolved` is deliberately true the moment `isAdmin` is true: a confirmed
|
|
85
188
|
* admin is a final answer, and the legs still in flight can only agree with it.
|
|
86
189
|
* Callers therefore never wait on a verdict they already have — an admin
|
|
87
|
-
* detected through `positions` pays nothing for this gate.
|
|
190
|
+
* detected through the rung or through `positions` pays nothing for this gate.
|
|
88
191
|
*/
|
|
89
192
|
export function useWorkspaceAdminStatus() {
|
|
90
193
|
const { activeMember, user, isLoading, isMembershipResolved } = useAuth();
|
|
91
194
|
const positions = user?.positions;
|
|
92
195
|
const isAdmin = isAdminRole(activeMember?.role) ||
|
|
93
196
|
isAdminRole(user?.role) ||
|
|
94
|
-
|
|
197
|
+
// Leg 3a — `=== true` on purpose. A session that never published the flag
|
|
198
|
+
// must read as "no platform standing", not as a truthy unknown.
|
|
199
|
+
user?.isPlatformAdmin === true ||
|
|
200
|
+
(Array.isArray(positions) && positions.some(isAdminPosition));
|
|
95
201
|
if (isAdmin)
|
|
96
202
|
return { isAdmin: true, isResolved: true };
|
|
97
|
-
// Legs 2 and
|
|
98
|
-
// is settled once the organization/member pipeline has reached a
|
|
99
|
-
// state (`isMembershipResolved`). Both, because a viewer can be an
|
|
100
|
-
// through either.
|
|
203
|
+
// Legs 2, 3a and 3b are settled once the session has landed (`isLoading`);
|
|
204
|
+
// leg 1 is settled once the organization/member pipeline has reached a
|
|
205
|
+
// terminal state (`isMembershipResolved`). Both, because a viewer can be an
|
|
206
|
+
// admin through either.
|
|
101
207
|
return { isAdmin: false, isResolved: !isLoading && isMembershipResolved };
|
|
102
208
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/auth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "18.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Authentication system for Object UI with AuthProvider, useAuth hook, AuthGuard, and form components.",
|
|
@@ -30,9 +30,8 @@
|
|
|
30
30
|
"react": "^18.0.0 || ^19.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@objectstack/spec": "^
|
|
34
|
-
"better-auth": "^1.
|
|
35
|
-
"@object-ui/types": "17.6.0"
|
|
33
|
+
"@objectstack/spec": "^18.0.0",
|
|
34
|
+
"better-auth": "^1.7.2"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
37
|
"@types/react": "19.2.18",
|
|
@@ -62,9 +61,9 @@
|
|
|
62
61
|
"access": "public"
|
|
63
62
|
},
|
|
64
63
|
"scripts": {
|
|
65
|
-
"build": "tsc",
|
|
66
|
-
"clean": "rm -rf dist",
|
|
67
|
-
"test": "vitest run",
|
|
64
|
+
"build": "tsc && node ../../scripts/check-dist-completeness.mjs",
|
|
65
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
66
|
+
"test": "vitest run --root ../.. packages/auth/",
|
|
68
67
|
"type-check": "tsc --noEmit && tsc -p tsconfig.test.json",
|
|
69
68
|
"lint": "eslint ."
|
|
70
69
|
}
|