@object-ui/auth 6.2.1 → 6.2.3
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
CHANGED
|
@@ -6,11 +6,15 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
|
-
* Returns true when the current user has owner/admin
|
|
10
|
-
* organization. Defaults to `false` until the active member row has loaded —
|
|
11
|
-
* this avoids flashing admin-only UI to regular members on first paint.
|
|
9
|
+
* Returns true when the current user has owner/admin privileges.
|
|
12
10
|
*
|
|
13
|
-
*
|
|
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,
|
|
14
18
|
* so this returns `true` for dev/demo setups.
|
|
15
19
|
*/
|
|
16
20
|
export declare function useIsWorkspaceAdmin(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsWorkspaceAdmin.d.ts","sourceRoot":"","sources":["../src/useIsWorkspaceAdmin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"useIsWorkspaceAdmin.d.ts","sourceRoot":"","sources":["../src/useIsWorkspaceAdmin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAM7C"}
|
|
@@ -6,16 +6,36 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
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
|
+
]);
|
|
17
|
+
function isAdminRole(role) {
|
|
18
|
+
return typeof role === 'string' && ADMIN_ROLES.has(role.toLowerCase());
|
|
19
|
+
}
|
|
9
20
|
/**
|
|
10
|
-
* Returns true when the current user has owner/admin
|
|
11
|
-
*
|
|
12
|
-
*
|
|
21
|
+
* Returns true when the current user has owner/admin privileges.
|
|
22
|
+
*
|
|
23
|
+
* Sources considered (any one is sufficient):
|
|
24
|
+
* - The active organization member row (multi-tenant mode).
|
|
25
|
+
* - The top-level `user.role` / `user.roles` from the session — this covers
|
|
26
|
+
* platform / system administrators in single-tenant deployments where
|
|
27
|
+
* there is no `activeMember` row to read a role from.
|
|
13
28
|
*
|
|
14
|
-
* In preview-mode / no-auth-enabled mode the provider seeds an admin
|
|
29
|
+
* In preview-mode / no-auth-enabled mode the provider seeds an admin user,
|
|
15
30
|
* so this returns `true` for dev/demo setups.
|
|
16
31
|
*/
|
|
17
32
|
export function useIsWorkspaceAdmin() {
|
|
18
|
-
const { activeMember } = useAuth();
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
const { activeMember, user } = useAuth();
|
|
34
|
+
if (isAdminRole(activeMember?.role))
|
|
35
|
+
return true;
|
|
36
|
+
if (isAdminRole(user?.role))
|
|
37
|
+
return true;
|
|
38
|
+
if (Array.isArray(user?.roles) && user.roles.some(isAdminRole))
|
|
39
|
+
return true;
|
|
40
|
+
return false;
|
|
21
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/auth",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Authentication system for Object UI with AuthProvider, useAuth hook, AuthGuard, and form components.",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"better-auth": "^1.6.11",
|
|
34
|
-
"@object-ui/types": "6.2.
|
|
34
|
+
"@object-ui/types": "6.2.3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/react": "19.2.15",
|