@object-ui/auth 17.3.0 → 17.6.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 +213 -0
- package/README.md +184 -13
- package/dist/ActiveOrganizationStorage.d.ts +168 -0
- package/dist/ActiveOrganizationStorage.d.ts.map +1 -0
- package/dist/ActiveOrganizationStorage.js +515 -0
- package/dist/AuthContext.d.ts +34 -1
- package/dist/AuthContext.d.ts.map +1 -1
- package/dist/AuthGuard.d.ts +8 -1
- package/dist/AuthGuard.d.ts.map +1 -1
- package/dist/AuthGuard.js +16 -3
- package/dist/AuthProvider.d.ts +1 -1
- package/dist/AuthProvider.d.ts.map +1 -1
- package/dist/AuthProvider.js +359 -32
- package/dist/ForgotPasswordForm.d.ts +1 -1
- package/dist/ForgotPasswordForm.d.ts.map +1 -1
- package/dist/ForgotPasswordForm.js +5 -5
- package/dist/LoginForm.d.ts +1 -1
- package/dist/LoginForm.d.ts.map +1 -1
- package/dist/LoginForm.js +4 -4
- package/dist/PreviewBanner.js +1 -1
- package/dist/RegisterForm.d.ts +1 -1
- package/dist/RegisterForm.d.ts.map +1 -1
- package/dist/RegisterForm.js +3 -3
- package/dist/SocialSignInButtons.js +2 -2
- package/dist/UserMenu.js +2 -2
- package/dist/createAuthClient.d.ts +23 -1
- package/dist/createAuthClient.d.ts.map +1 -1
- package/dist/createAuthClient.js +112 -25
- package/dist/createAuthenticatedFetch.d.ts +9 -9
- package/dist/createAuthenticatedFetch.d.ts.map +1 -1
- package/dist/createAuthenticatedFetch.js +82 -37
- package/dist/index.d.ts +20 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -17
- package/dist/invitation-status.d.ts +59 -0
- package/dist/invitation-status.d.ts.map +1 -0
- package/dist/invitation-status.js +32 -0
- package/dist/types.d.ts +52 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/useAuth.d.ts +1 -1
- package/dist/useAuth.d.ts.map +1 -1
- package/dist/useAuth.js +6 -1
- package/dist/useWorkspaceAdminStatus.d.ts +85 -0
- package/dist/useWorkspaceAdminStatus.d.ts.map +1 -0
- package/dist/useWorkspaceAdminStatus.js +102 -0
- package/package.json +5 -5
- package/dist/useIsWorkspaceAdmin.d.ts +0 -21
- package/dist/useIsWorkspaceAdmin.d.ts.map +0 -1
- package/dist/useIsWorkspaceAdmin.js +0 -47
package/dist/index.js
CHANGED
|
@@ -19,27 +19,38 @@
|
|
|
19
19
|
*
|
|
20
20
|
* @packageDocumentation
|
|
21
21
|
*/
|
|
22
|
-
export { AuthProvider } from './AuthProvider';
|
|
23
|
-
export { useAuth } from './useAuth';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
22
|
+
export { AuthProvider } from './AuthProvider.js';
|
|
23
|
+
export { useAuth } from './useAuth.js';
|
|
24
|
+
// objectui#5619 — replaces `useIsWorkspaceAdmin(): boolean`, which had no way
|
|
25
|
+
// to say "not resolved yet" and so answered "not an admin" about an
|
|
26
|
+
// administrator whose adminship lives only in the active member row. The old
|
|
27
|
+
// name is REMOVED rather than kept alongside: a caller that misses the third
|
|
28
|
+
// state is the whole defect, and a deleted export makes that a compile error
|
|
29
|
+
// instead of a silent access-denied screen.
|
|
30
|
+
export { useWorkspaceAdminStatus } from './useWorkspaceAdminStatus.js';
|
|
31
|
+
export { AuthGuard } from './AuthGuard.js';
|
|
32
|
+
export { AuthShell } from './AuthShell.js';
|
|
33
|
+
export { LoginForm } from './LoginForm.js';
|
|
34
|
+
export { RegisterForm } from './RegisterForm.js';
|
|
35
|
+
export { ForgotPasswordForm } from './ForgotPasswordForm.js';
|
|
36
|
+
export { SocialSignInButtons } from './SocialSignInButtons.js';
|
|
37
|
+
export { UserMenu } from './UserMenu.js';
|
|
38
|
+
export { PreviewBanner } from './PreviewBanner.js';
|
|
39
|
+
export { createAuthClient, TokenStorage } from './createAuthClient.js';
|
|
40
|
+
export { normalizePhoneIdentifier, looksLikePhoneIdentifier } from './phone-identifier.js';
|
|
41
|
+
export { createAuthenticatedFetch, ActiveOrganizationStorage } from './createAuthenticatedFetch.js';
|
|
42
|
+
export { getUserInitials } from './types.js';
|
|
37
43
|
// Organization membership-role vocabulary — a CLOSED, framework-owned list of
|
|
38
44
|
// four (framework ADR-0108), re-exported from `@objectstack/spec`'s
|
|
39
45
|
// `BUILTIN_MEMBERSHIP_ROLES` so it cannot drift — plus the labels and
|
|
40
46
|
// narrowing helpers every org screen shares, which stay console-owned
|
|
41
47
|
// (see `org-roles.ts` for the boundary).
|
|
42
|
-
export { ORG_ROLE_OWNER, ORG_ROLE_ADMIN, ORG_ROLE_DELEGATED_ADMIN, ORG_ROLE_MEMBER, ORG_ROLES, ORG_ROLE_LABELS, orgRoleGrade, invitableOrgRoles, assignableOrgRoles, } from './org-roles';
|
|
48
|
+
export { ORG_ROLE_OWNER, ORG_ROLE_ADMIN, ORG_ROLE_DELEGATED_ADMIN, ORG_ROLE_MEMBER, ORG_ROLES, ORG_ROLE_LABELS, orgRoleGrade, invitableOrgRoles, assignableOrgRoles, } from './org-roles.js';
|
|
49
|
+
// Invitation lifecycle vocabulary — a CLOSED set of four, bound to better-auth's
|
|
50
|
+
// own `InvitationStatus` so it cannot drift, plus the narrowing guard the wire
|
|
51
|
+
// boundary uses. Exported because a screen switching on `AuthInvitation.status`
|
|
52
|
+
// needs the union by name (objectui#3879).
|
|
53
|
+
export { AUTH_INVITATION_STATUSES, isAuthInvitationStatus, } from './invitation-status.js';
|
|
43
54
|
// Shared auth form primitives — exposed so consumers can build custom forms
|
|
44
55
|
// that match the look of LoginForm / RegisterForm / ForgotPasswordForm.
|
|
45
|
-
export { AUTH_FIELD_LABEL_CLASS, AUTH_INPUT_CLASS, AUTH_LINK_CLASS, AUTH_PRIMARY_BUTTON_CLASS, AuthAlertIcon, AuthCheckIcon, AuthDivider, AuthErrorBanner, AuthFormHeader, AuthMailIcon, AuthSpinner, } from './authStyles';
|
|
56
|
+
export { AUTH_FIELD_LABEL_CLASS, AUTH_INPUT_CLASS, AUTH_LINK_CLASS, AUTH_PRIMARY_BUTTON_CLASS, AuthAlertIcon, AuthCheckIcon, AuthDivider, AuthErrorBanner, AuthFormHeader, AuthMailIcon, AuthSpinner, } from './authStyles.js';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Invitation status vocabulary — the console's ONE entry point for it.
|
|
10
|
+
*
|
|
11
|
+
* ## Why this is a module and not a doc comment
|
|
12
|
+
*
|
|
13
|
+
* `AuthInvitation.status` was declared as an open `string` while its own doc
|
|
14
|
+
* comment enumerated exactly four members (objectui#3879). A comment cannot be
|
|
15
|
+
* enforced, so every consumer had to be liberal in turn: `InvitationsPage`
|
|
16
|
+
* carried a `default: 'secondary'` arm in its badge-variant switch and a
|
|
17
|
+
* `defaultValue: inv.status` that would render the raw wire string as UI copy —
|
|
18
|
+
* in all ten packs — for any value the enumeration did not cover. Declared =
|
|
19
|
+
* enforced (AGENTS.md #0.1): the union now lives in the type, and the wire
|
|
20
|
+
* boundary in `createAuthClient` is the one place an unvalidated string may
|
|
21
|
+
* become one.
|
|
22
|
+
*
|
|
23
|
+
* ## The vocabulary is CLOSED — and derived, not mirrored
|
|
24
|
+
*
|
|
25
|
+
* The producer is better-auth's organization plugin, whose own
|
|
26
|
+
* `InvitationStatus` is `'pending' | 'accepted' | 'rejected' | 'canceled'`
|
|
27
|
+
* (`better-auth/client/plugins`; the framework stores it in
|
|
28
|
+
* `sys_invitation.status`). This module BINDS that type instead of restating it,
|
|
29
|
+
* for the same reason `org-roles.ts` binds the spec's
|
|
30
|
+
* `BUILTIN_MEMBERSHIP_ROLES`: a member-for-member copy is precisely the state
|
|
31
|
+
* one upstream release away from drifting silently.
|
|
32
|
+
*
|
|
33
|
+
* The runtime list is derived from a total `Record` keyed by that union, so the
|
|
34
|
+
* compile-time half and the runtime half cannot disagree — a fifth status
|
|
35
|
+
* upstream fails to compile HERE (the map is missing a key) rather than slipping
|
|
36
|
+
* past the boundary check and out onto a badge.
|
|
37
|
+
*
|
|
38
|
+
* What stays LOCAL, deliberately: everything about *display*. The filter tabs'
|
|
39
|
+
* `StatusFilter` (which adds an `all` pseudo-member) and the badge variants are
|
|
40
|
+
* screen concerns and live with the screen — the same boundary `org-roles.ts`
|
|
41
|
+
* draws for its labels and grade ladder.
|
|
42
|
+
*/
|
|
43
|
+
import type { InvitationStatus } from 'better-auth/client/plugins';
|
|
44
|
+
/**
|
|
45
|
+
* Status an organization invitation can carry — better-auth's own union, bound
|
|
46
|
+
* rather than copied.
|
|
47
|
+
*/
|
|
48
|
+
export type AuthInvitationStatus = InvitationStatus;
|
|
49
|
+
/** Every status an invitation can carry, in the order the screens list them. */
|
|
50
|
+
export declare const AUTH_INVITATION_STATUSES: readonly AuthInvitationStatus[];
|
|
51
|
+
/**
|
|
52
|
+
* Narrow an unvalidated wire value onto the closed status set.
|
|
53
|
+
*
|
|
54
|
+
* The ONE place a `string` may become an `AuthInvitationStatus`. Everything
|
|
55
|
+
* downstream reads the narrowed type and therefore needs no fallback arm — which
|
|
56
|
+
* is the whole point: a tolerant consumer is where an unexpected value hides.
|
|
57
|
+
*/
|
|
58
|
+
export declare function isAuthInvitationStatus(value: unknown): value is AuthInvitationStatus;
|
|
59
|
+
//# sourceMappingURL=invitation-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invitation-status.d.ts","sourceRoot":"","sources":["../src/invitation-status.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAcpD,gFAAgF;AAChF,eAAO,MAAM,wBAAwB,EAAE,SAAS,oBAAoB,EACrC,CAAC;AAKhC;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAEpF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Total map over the union — the compile-time half of the pin. Values are the
|
|
10
|
+
* members themselves so the runtime list below is DERIVED rather than restated
|
|
11
|
+
* (one literal list, not two).
|
|
12
|
+
*/
|
|
13
|
+
const STATUS_MEMBERS = {
|
|
14
|
+
pending: 'pending',
|
|
15
|
+
accepted: 'accepted',
|
|
16
|
+
rejected: 'rejected',
|
|
17
|
+
canceled: 'canceled',
|
|
18
|
+
};
|
|
19
|
+
/** Every status an invitation can carry, in the order the screens list them. */
|
|
20
|
+
export const AUTH_INVITATION_STATUSES = Object.values(STATUS_MEMBERS);
|
|
21
|
+
/** Membership test backing the guard. `Set` so the check stays O(1) per row. */
|
|
22
|
+
const STATUS_LOOKUP = new Set(AUTH_INVITATION_STATUSES);
|
|
23
|
+
/**
|
|
24
|
+
* Narrow an unvalidated wire value onto the closed status set.
|
|
25
|
+
*
|
|
26
|
+
* The ONE place a `string` may become an `AuthInvitationStatus`. Everything
|
|
27
|
+
* downstream reads the narrowed type and therefore needs no fallback arm — which
|
|
28
|
+
* is the whole point: a tolerant consumer is where an unexpected value hides.
|
|
29
|
+
*/
|
|
30
|
+
export function isAuthInvitationStatus(value) {
|
|
31
|
+
return typeof value === 'string' && STATUS_LOOKUP.has(value);
|
|
32
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type React from 'react';
|
|
9
9
|
import type { AuthUser as SpecAuthUser, DelegableScope, DelegableAdminScope } from '@objectstack/spec/contracts';
|
|
10
10
|
import type { TenancyPosture } from '@objectstack/spec/security';
|
|
11
|
+
import type { AuthInvitationStatus } from './invitation-status.js';
|
|
11
12
|
/**
|
|
12
13
|
* Authentication types for @object-ui/auth
|
|
13
14
|
*/
|
|
@@ -55,8 +56,6 @@ export interface AuthUser extends SpecAuthUser {
|
|
|
55
56
|
image?: string;
|
|
56
57
|
/** Primary role */
|
|
57
58
|
role?: string;
|
|
58
|
-
/** All assigned roles */
|
|
59
|
-
roles?: string[];
|
|
60
59
|
/** Email verification status */
|
|
61
60
|
emailVerified?: boolean;
|
|
62
61
|
/** Additional user metadata */
|
|
@@ -85,6 +84,18 @@ export interface AuthClientSession {
|
|
|
85
84
|
expiresAt?: Date;
|
|
86
85
|
/** Refresh token */
|
|
87
86
|
refreshToken?: string;
|
|
87
|
+
/**
|
|
88
|
+
* objectui#4467 — set by better-auth's admin plugin while this session is an
|
|
89
|
+
* IMPERSONATION: the id of the administrator who started it. Present on
|
|
90
|
+
* `GET /auth/get-session` for the whole life of the impersonated session, so
|
|
91
|
+
* a console that reads it survives full SPA reboots (it is a property of the
|
|
92
|
+
* session, not a memory of the click that created it).
|
|
93
|
+
*
|
|
94
|
+
* Its presence is what raises the impersonation banner — see
|
|
95
|
+
* `@object-ui/app-shell`'s `ImpersonationBanner`. Absent on every ordinary
|
|
96
|
+
* session, which is why the banner costs a normal session nothing.
|
|
97
|
+
*/
|
|
98
|
+
impersonatedBy?: string;
|
|
88
99
|
}
|
|
89
100
|
/** Authentication state */
|
|
90
101
|
export interface AuthState {
|
|
@@ -138,7 +149,36 @@ export interface AuthPublicConfig {
|
|
|
138
149
|
socialProviders?: AuthSocialProvider[];
|
|
139
150
|
features?: {
|
|
140
151
|
twoFactor?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* RESERVED — declared so the `/auth/config` payload types cleanly, and
|
|
154
|
+
* consumed by nothing in this repository. Enabling it server-side adds
|
|
155
|
+
* **no** passkey entry point to the login page, because there is no passkey
|
|
156
|
+
* sign-in or registration UI for it to gate. Contrast `sso`,
|
|
157
|
+
* `phoneNumberOtp` and `deviceAuthorization` below, which each gate a real
|
|
158
|
+
* surface.
|
|
159
|
+
*
|
|
160
|
+
* Building the flow is objectui#4179, filed unscheduled. This marking
|
|
161
|
+
* follows the maintainer's 2026-08-03 ruling on objectui#2514: document the
|
|
162
|
+
* flag as reserved now, build the UI when the login surface gets roadmap
|
|
163
|
+
* time (at which point it renders driven by this flag).
|
|
164
|
+
*
|
|
165
|
+
* Pinned by `__tests__/reserved-auth-features.test.ts`. That pin fails the
|
|
166
|
+
* moment a consumer appears, because the declaration, this doc comment and
|
|
167
|
+
* `README.md`'s reserved section have to retire in one PR — see the pin's
|
|
168
|
+
* docblock for the retirement checklist.
|
|
169
|
+
*/
|
|
141
170
|
passkeys?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* RESERVED — declared so the `/auth/config` payload types cleanly, and
|
|
173
|
+
* consumed by nothing in this repository. Enabling it server-side adds
|
|
174
|
+
* **no** "email me a sign-in link" entry point to the login page: there is
|
|
175
|
+
* neither a magic-link request step nor a route that consumes the emailed
|
|
176
|
+
* token.
|
|
177
|
+
*
|
|
178
|
+
* Same ruling, same follow-up card and same pin as `passkeys` above
|
|
179
|
+
* (objectui#2514 / objectui#4179 /
|
|
180
|
+
* `__tests__/reserved-auth-features.test.ts`).
|
|
181
|
+
*/
|
|
142
182
|
magicLink?: boolean;
|
|
143
183
|
organization?: boolean;
|
|
144
184
|
/**
|
|
@@ -401,8 +441,16 @@ export interface AuthInvitation {
|
|
|
401
441
|
email: string;
|
|
402
442
|
/** Role to be granted upon acceptance */
|
|
403
443
|
role: string;
|
|
404
|
-
/**
|
|
405
|
-
|
|
444
|
+
/**
|
|
445
|
+
* Lifecycle status, as the CLOSED set better-auth stores.
|
|
446
|
+
*
|
|
447
|
+
* Was an open `string` with the four members living in this comment, which
|
|
448
|
+
* left every consumer to be liberal about the fifth value that comment could
|
|
449
|
+
* not forbid (objectui#3879). The union is `AuthInvitationStatus` now, and
|
|
450
|
+
* `createAuthClient` narrows the wire value onto it at the boundary — so a
|
|
451
|
+
* screen reading this field can switch on it exhaustively.
|
|
452
|
+
*/
|
|
453
|
+
status: AuthInvitationStatus;
|
|
406
454
|
/** Expiration timestamp */
|
|
407
455
|
expiresAt?: string;
|
|
408
456
|
/** ID of the inviting user */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,QAAQ,IAAI,YAAY,EACxB,cAAc,EACd,mBAAmB,EACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,QAAQ,IAAI,YAAY,EACxB,cAAc,EACd,mBAAmB,EACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,YAAY,EAAE,cAAc,EAA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AAC,EAAE,MAAM,CAAC;CACrB"}
|
package/dist/useAuth.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
import { type AuthContextValue } from './AuthContext';
|
|
8
|
+
import { type AuthContextValue } from './AuthContext.js';
|
|
9
9
|
/**
|
|
10
10
|
* Hook to access authentication state and methods.
|
|
11
11
|
* Must be used within an AuthProvider.
|
package/dist/useAuth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../src/useAuth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../src/useAuth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAElE;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,IAAI,gBAAgB,CAiE1C"}
|
package/dist/useAuth.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import { useContext } from 'react';
|
|
9
|
-
import { AuthCtx } from './AuthContext';
|
|
9
|
+
import { AuthCtx } from './AuthContext.js';
|
|
10
10
|
/**
|
|
11
11
|
* Hook to access authentication state and methods.
|
|
12
12
|
* Must be used within an AuthProvider.
|
|
@@ -36,6 +36,7 @@ export function useAuth() {
|
|
|
36
36
|
signIn: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
37
37
|
signUp: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
38
38
|
signOut: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
39
|
+
refreshSession: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
39
40
|
updateUser: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
40
41
|
forgotPassword: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
41
42
|
sendVerificationEmail: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
@@ -59,6 +60,10 @@ export function useAuth() {
|
|
|
59
60
|
activeOrganization: null,
|
|
60
61
|
activeMember: null,
|
|
61
62
|
isOrganizationsLoading: false,
|
|
63
|
+
// Nothing to resolve without a provider — same reasoning as `isLoading`
|
|
64
|
+
// above, which is `false` here for the same reason. A consumer gating on
|
|
65
|
+
// this must render through in a provider-less embed, not hang.
|
|
66
|
+
isMembershipResolved: true,
|
|
62
67
|
switchOrganization: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
63
68
|
createOrganization: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
64
69
|
refreshOrganizations: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The workspace-admin verdict AND whether it is worth acting on yet.
|
|
10
|
+
*
|
|
11
|
+
* These are two different facts and they were one boolean until objectui#5619.
|
|
12
|
+
* See {@link useWorkspaceAdminStatus} for why collapsing them was a defect.
|
|
13
|
+
*/
|
|
14
|
+
export interface WorkspaceAdminStatus {
|
|
15
|
+
/**
|
|
16
|
+
* True only when adminship is CONFIRMED by one of the three legs below.
|
|
17
|
+
* While `isResolved` is false this is `false` because nothing has said
|
|
18
|
+
* otherwise yet — NOT because the viewer is known not to be an admin.
|
|
19
|
+
*/
|
|
20
|
+
isAdmin: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether every input `isAdmin` depends on has arrived. Gate any branch
|
|
23
|
+
* whose wrong side is expensive — a refusal screen, a `<Navigate>`, a nav
|
|
24
|
+
* entry that would have to be added back — on this being true.
|
|
25
|
+
*/
|
|
26
|
+
isResolved: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether the current user has owner/admin privileges, and whether that answer
|
|
30
|
+
* has finished resolving.
|
|
31
|
+
*
|
|
32
|
+
* Sources considered (any one is sufficient):
|
|
33
|
+
* - The active organization member row (multi-tenant mode).
|
|
34
|
+
* - The top-level `user.role` scalar from the session — legacy deployments
|
|
35
|
+
* that still store an admin role on the user row.
|
|
36
|
+
* - `user.positions[]` from the session — the canonical identity/position
|
|
37
|
+
* names the server derives (ADR-0068 D1/D2, renamed from `roles` by
|
|
38
|
+
* ADR-0090 D3). This is the ONLY leg that sees a platform administrator
|
|
39
|
+
* whose adminship comes from the `admin_full_access` permission set: on a
|
|
40
|
+
* single-tenant deployment there is no member row to read (leg 1), and the
|
|
41
|
+
* server deliberately no longer overwrites `user.role` (leg 2), so
|
|
42
|
+
* `positions` carrying `platform_admin` is the whole signal. Measured on a
|
|
43
|
+
* live protocol-17 server in objectui#5389; pinned by
|
|
44
|
+
* `__tests__/workspaceAdminPositions-5389.test.tsx`.
|
|
45
|
+
*
|
|
46
|
+
* `positions` is the ONE published spelling. It is deliberately not read
|
|
47
|
+
* alongside the retired `roles` (ADR-0090 D3 renamed with no deprecation
|
|
48
|
+
* window and bans resurrecting the old name as a fallback), and not alongside
|
|
49
|
+
* the derived `user.isPlatformAdmin` either — that flag is computed by the
|
|
50
|
+
* server as `'platform_admin' in positions` from the same expression, so
|
|
51
|
+
* reading both would be two spellings for one fact with no way to disagree
|
|
52
|
+
* usefully and every way to drift.
|
|
53
|
+
*
|
|
54
|
+
* In preview-mode / no-auth-enabled mode the provider seeds an admin user,
|
|
55
|
+
* so this returns `isAdmin: true` for dev/demo setups.
|
|
56
|
+
*
|
|
57
|
+
* ## Why this returns a pair and not a boolean (objectui#5619)
|
|
58
|
+
*
|
|
59
|
+
* It used to return a bare `boolean`, which gave "not resolved yet" and
|
|
60
|
+
* "resolved: not an admin" the same answer — `false`. Leg 1 is not settled
|
|
61
|
+
* when a console page first mounts: `AuthProvider.refreshActiveMember` runs
|
|
62
|
+
* from its own effect, keyed on `activeOrganization`, which itself appears
|
|
63
|
+
* only after `listOrganizations()` → `getActiveOrganization()` (→ the ADR-0081
|
|
64
|
+
* single-membership `setActiveOrganization()` repair) resolve. So an
|
|
65
|
+
* administrator whose adminship lives ONLY in the member row rendered at least
|
|
66
|
+
* once as a non-admin, and every gate downstream acted on it: two marketplace
|
|
67
|
+
* surfaces painted `MarketplaceAccessDenied` at a real administrator, the
|
|
68
|
+
* console chrome dropped and re-added a nav entry, and `AppContent` fired a
|
|
69
|
+
* `<Navigate to="/home" replace>` that the later flip cannot undo.
|
|
70
|
+
*
|
|
71
|
+
* Legs 2 and 3 DO cover that viewer whenever the session was minted with an
|
|
72
|
+
* active organization stamped on it — framework `auth-manager.ts` reads
|
|
73
|
+
* `session.activeOrganizationId` and, when it is set, maps the member row into
|
|
74
|
+
* `positions[]` as `org_owner`/`org_admin`. The window is therefore not "every
|
|
75
|
+
* tenant admin" as first reported, but "every session that reaches the console
|
|
76
|
+
* without that stamp", which is exactly the path `refreshOrganizations`'
|
|
77
|
+
* ADR-0081 repair exists to serve.
|
|
78
|
+
*
|
|
79
|
+
* `isResolved` is deliberately true the moment `isAdmin` is true: a confirmed
|
|
80
|
+
* admin is a final answer, and the legs still in flight can only agree with it.
|
|
81
|
+
* Callers therefore never wait on a verdict they already have — an admin
|
|
82
|
+
* detected through `positions` pays nothing for this gate.
|
|
83
|
+
*/
|
|
84
|
+
export declare function useWorkspaceAdminStatus(): WorkspaceAdminStatus;
|
|
85
|
+
//# sourceMappingURL=useWorkspaceAdminStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWorkspaceAdminStatus.d.ts","sourceRoot":"","sources":["../src/useWorkspaceAdminStatus.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA8BH;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,uBAAuB,IAAI,oBAAoB,CAgB9D"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { useAuth } from './useAuth.js';
|
|
9
|
+
const ADMIN_ROLES = new Set([
|
|
10
|
+
'owner',
|
|
11
|
+
'admin',
|
|
12
|
+
'super_admin',
|
|
13
|
+
'superadmin',
|
|
14
|
+
'platform_admin',
|
|
15
|
+
'system_admin',
|
|
16
|
+
// ADR-0068 canonical names, emitted into `user.positions[]` by the server's
|
|
17
|
+
// customSession (raw better-auth owner/admin are normalized to org_owner/
|
|
18
|
+
// org_admin). Accept both raw and canonical so admin detection survives the
|
|
19
|
+
// removal of the `user.role = 'admin'` overwrite footgun.
|
|
20
|
+
'org_owner',
|
|
21
|
+
'org_admin',
|
|
22
|
+
]);
|
|
23
|
+
/**
|
|
24
|
+
* One name from any of the three sources below — a membership role, the stored
|
|
25
|
+
* `user.role` scalar, or an entry of `user.positions[]`. The three draw on one
|
|
26
|
+
* vocabulary by design (ADR-0068 D2 maps a membership `owner`/`admin` onto the
|
|
27
|
+
* canonical `org_owner`/`org_admin` that `positions[]` carries), so one
|
|
28
|
+
* predicate serves all three.
|
|
29
|
+
*/
|
|
30
|
+
function isAdminRole(role) {
|
|
31
|
+
return typeof role === 'string' && ADMIN_ROLES.has(role.toLowerCase());
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether the current user has owner/admin privileges, and whether that answer
|
|
35
|
+
* has finished resolving.
|
|
36
|
+
*
|
|
37
|
+
* Sources considered (any one is sufficient):
|
|
38
|
+
* - The active organization member row (multi-tenant mode).
|
|
39
|
+
* - The top-level `user.role` scalar from the session — legacy deployments
|
|
40
|
+
* that still store an admin role on the user row.
|
|
41
|
+
* - `user.positions[]` from the session — the canonical identity/position
|
|
42
|
+
* names the server derives (ADR-0068 D1/D2, renamed from `roles` by
|
|
43
|
+
* ADR-0090 D3). This is the ONLY leg that sees a platform administrator
|
|
44
|
+
* whose adminship comes from the `admin_full_access` permission set: on a
|
|
45
|
+
* single-tenant deployment there is no member row to read (leg 1), and the
|
|
46
|
+
* server deliberately no longer overwrites `user.role` (leg 2), so
|
|
47
|
+
* `positions` carrying `platform_admin` is the whole signal. Measured on a
|
|
48
|
+
* live protocol-17 server in objectui#5389; pinned by
|
|
49
|
+
* `__tests__/workspaceAdminPositions-5389.test.tsx`.
|
|
50
|
+
*
|
|
51
|
+
* `positions` is the ONE published spelling. It is deliberately not read
|
|
52
|
+
* alongside the retired `roles` (ADR-0090 D3 renamed with no deprecation
|
|
53
|
+
* window and bans resurrecting the old name as a fallback), and not alongside
|
|
54
|
+
* the derived `user.isPlatformAdmin` either — that flag is computed by the
|
|
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.
|
|
58
|
+
*
|
|
59
|
+
* In preview-mode / no-auth-enabled mode the provider seeds an admin user,
|
|
60
|
+
* so this returns `isAdmin: true` for dev/demo setups.
|
|
61
|
+
*
|
|
62
|
+
* ## Why this returns a pair and not a boolean (objectui#5619)
|
|
63
|
+
*
|
|
64
|
+
* It used to return a bare `boolean`, which gave "not resolved yet" and
|
|
65
|
+
* "resolved: not an admin" the same answer — `false`. Leg 1 is not settled
|
|
66
|
+
* when a console page first mounts: `AuthProvider.refreshActiveMember` runs
|
|
67
|
+
* from its own effect, keyed on `activeOrganization`, which itself appears
|
|
68
|
+
* only after `listOrganizations()` → `getActiveOrganization()` (→ the ADR-0081
|
|
69
|
+
* single-membership `setActiveOrganization()` repair) resolve. So an
|
|
70
|
+
* administrator whose adminship lives ONLY in the member row rendered at least
|
|
71
|
+
* once as a non-admin, and every gate downstream acted on it: two marketplace
|
|
72
|
+
* surfaces painted `MarketplaceAccessDenied` at a real administrator, the
|
|
73
|
+
* console chrome dropped and re-added a nav entry, and `AppContent` fired a
|
|
74
|
+
* `<Navigate to="/home" replace>` that the later flip cannot undo.
|
|
75
|
+
*
|
|
76
|
+
* Legs 2 and 3 DO cover that viewer whenever the session was minted with an
|
|
77
|
+
* active organization stamped on it — framework `auth-manager.ts` reads
|
|
78
|
+
* `session.activeOrganizationId` and, when it is set, maps the member row into
|
|
79
|
+
* `positions[]` as `org_owner`/`org_admin`. The window is therefore not "every
|
|
80
|
+
* tenant admin" as first reported, but "every session that reaches the console
|
|
81
|
+
* without that stamp", which is exactly the path `refreshOrganizations`'
|
|
82
|
+
* ADR-0081 repair exists to serve.
|
|
83
|
+
*
|
|
84
|
+
* `isResolved` is deliberately true the moment `isAdmin` is true: a confirmed
|
|
85
|
+
* admin is a final answer, and the legs still in flight can only agree with it.
|
|
86
|
+
* Callers therefore never wait on a verdict they already have — an admin
|
|
87
|
+
* detected through `positions` pays nothing for this gate.
|
|
88
|
+
*/
|
|
89
|
+
export function useWorkspaceAdminStatus() {
|
|
90
|
+
const { activeMember, user, isLoading, isMembershipResolved } = useAuth();
|
|
91
|
+
const positions = user?.positions;
|
|
92
|
+
const isAdmin = isAdminRole(activeMember?.role) ||
|
|
93
|
+
isAdminRole(user?.role) ||
|
|
94
|
+
(Array.isArray(positions) && positions.some(isAdminRole));
|
|
95
|
+
if (isAdmin)
|
|
96
|
+
return { isAdmin: true, isResolved: true };
|
|
97
|
+
// Legs 2 and 3 are settled once the session has landed (`isLoading`); leg 1
|
|
98
|
+
// is settled once the organization/member pipeline has reached a terminal
|
|
99
|
+
// state (`isMembershipResolved`). Both, because a viewer can be an admin
|
|
100
|
+
// through either.
|
|
101
|
+
return { isAdmin: false, isResolved: !isLoading && isMembershipResolved };
|
|
102
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/auth",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.6.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,9 @@
|
|
|
30
30
|
"react": "^18.0.0 || ^19.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@objectstack/spec": "^17.0.0
|
|
34
|
-
"better-auth": "^1.6.
|
|
35
|
-
"@object-ui/types": "17.
|
|
33
|
+
"@objectstack/spec": "^17.0.0",
|
|
34
|
+
"better-auth": "^1.6.28",
|
|
35
|
+
"@object-ui/types": "17.6.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/react": "19.2.18",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"build": "tsc",
|
|
66
66
|
"clean": "rm -rf dist",
|
|
67
67
|
"test": "vitest run",
|
|
68
|
-
"type-check": "tsc --noEmit && tsc -p tsconfig.
|
|
68
|
+
"type-check": "tsc --noEmit && tsc -p tsconfig.test.json",
|
|
69
69
|
"lint": "eslint ."
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Returns true when the current user has owner/admin privileges.
|
|
10
|
-
*
|
|
11
|
-
* Sources considered (any one is sufficient):
|
|
12
|
-
* - The active organization member row (multi-tenant mode).
|
|
13
|
-
* - The top-level `user.role` / `user.roles` from the session — this covers
|
|
14
|
-
* platform / system administrators in single-tenant deployments where
|
|
15
|
-
* there is no `activeMember` row to read a role from.
|
|
16
|
-
*
|
|
17
|
-
* In preview-mode / no-auth-enabled mode the provider seeds an admin user,
|
|
18
|
-
* so this returns `true` for dev/demo setups.
|
|
19
|
-
*/
|
|
20
|
-
export declare function useIsWorkspaceAdmin(): boolean;
|
|
21
|
-
//# sourceMappingURL=useIsWorkspaceAdmin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIsWorkspaceAdmin.d.ts","sourceRoot":"","sources":["../src/useIsWorkspaceAdmin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAM7C"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
import { useAuth } from './useAuth';
|
|
9
|
-
const ADMIN_ROLES = new Set([
|
|
10
|
-
'owner',
|
|
11
|
-
'admin',
|
|
12
|
-
'super_admin',
|
|
13
|
-
'superadmin',
|
|
14
|
-
'platform_admin',
|
|
15
|
-
'system_admin',
|
|
16
|
-
// ADR-0068 canonical role names emitted into `user.roles[]` by the server
|
|
17
|
-
// customSession (raw better-auth owner/admin are normalized to org_owner/
|
|
18
|
-
// org_admin). Accept both raw and canonical so admin detection survives the
|
|
19
|
-
// removal of the `user.role = 'admin'` overwrite footgun.
|
|
20
|
-
'org_owner',
|
|
21
|
-
'org_admin',
|
|
22
|
-
]);
|
|
23
|
-
function isAdminRole(role) {
|
|
24
|
-
return typeof role === 'string' && ADMIN_ROLES.has(role.toLowerCase());
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns true when the current user has owner/admin privileges.
|
|
28
|
-
*
|
|
29
|
-
* Sources considered (any one is sufficient):
|
|
30
|
-
* - The active organization member row (multi-tenant mode).
|
|
31
|
-
* - The top-level `user.role` / `user.roles` from the session — this covers
|
|
32
|
-
* platform / system administrators in single-tenant deployments where
|
|
33
|
-
* there is no `activeMember` row to read a role from.
|
|
34
|
-
*
|
|
35
|
-
* In preview-mode / no-auth-enabled mode the provider seeds an admin user,
|
|
36
|
-
* so this returns `true` for dev/demo setups.
|
|
37
|
-
*/
|
|
38
|
-
export function useIsWorkspaceAdmin() {
|
|
39
|
-
const { activeMember, user } = useAuth();
|
|
40
|
-
if (isAdminRole(activeMember?.role))
|
|
41
|
-
return true;
|
|
42
|
-
if (isAdminRole(user?.role))
|
|
43
|
-
return true;
|
|
44
|
-
if (Array.isArray(user?.roles) && user.roles.some(isAdminRole))
|
|
45
|
-
return true;
|
|
46
|
-
return false;
|
|
47
|
-
}
|