@object-ui/auth 17.5.0 → 17.7.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 +600 -0
- package/README.md +245 -15
- package/dist/ActiveOrganizationStorage.d.ts +199 -0
- package/dist/ActiveOrganizationStorage.d.ts.map +1 -0
- package/dist/ActiveOrganizationStorage.js +584 -0
- package/dist/AuthContext.d.ts +23 -3
- 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 +274 -9
- 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 +11 -2
- package/dist/LoginForm.d.ts.map +1 -1
- package/dist/LoginForm.js +5 -6
- package/dist/PreviewBanner.js +1 -1
- package/dist/RegisterForm.d.ts +22 -3
- package/dist/RegisterForm.d.ts.map +1 -1
- package/dist/RegisterForm.js +6 -7
- package/dist/SocialSignInButtons.d.ts +9 -2
- package/dist/SocialSignInButtons.d.ts.map +1 -1
- package/dist/SocialSignInButtons.js +5 -5
- package/dist/UserMenu.d.ts +1 -1
- package/dist/UserMenu.js +3 -3
- package/dist/createAuthClient.d.ts +1 -1
- package/dist/createAuthClient.d.ts.map +1 -1
- package/dist/createAuthClient.js +42 -4
- package/dist/createAuthenticatedFetch.d.ts +9 -9
- package/dist/createAuthenticatedFetch.d.ts.map +1 -1
- package/dist/createAuthenticatedFetch.js +50 -38
- package/dist/index.d.ts +21 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -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 +25 -5
- 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 +5 -1
- package/dist/useWorkspaceAdminStatus.d.ts +134 -0
- package/dist/useWorkspaceAdminStatus.d.ts.map +1 -0
- package/dist/useWorkspaceAdminStatus.js +208 -0
- package/package.json +6 -7
- package/dist/useIsWorkspaceAdmin.d.ts +0 -21
- package/dist/useIsWorkspaceAdmin.d.ts.map +0 -1
- package/dist/useIsWorkspaceAdmin.js +0 -47
|
@@ -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
|
-
}
|