@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.
Files changed (52) hide show
  1. package/CHANGELOG.md +600 -0
  2. package/README.md +245 -15
  3. package/dist/ActiveOrganizationStorage.d.ts +199 -0
  4. package/dist/ActiveOrganizationStorage.d.ts.map +1 -0
  5. package/dist/ActiveOrganizationStorage.js +584 -0
  6. package/dist/AuthContext.d.ts +23 -3
  7. package/dist/AuthContext.d.ts.map +1 -1
  8. package/dist/AuthGuard.d.ts +8 -1
  9. package/dist/AuthGuard.d.ts.map +1 -1
  10. package/dist/AuthGuard.js +16 -3
  11. package/dist/AuthProvider.d.ts +1 -1
  12. package/dist/AuthProvider.d.ts.map +1 -1
  13. package/dist/AuthProvider.js +274 -9
  14. package/dist/ForgotPasswordForm.d.ts +1 -1
  15. package/dist/ForgotPasswordForm.d.ts.map +1 -1
  16. package/dist/ForgotPasswordForm.js +5 -5
  17. package/dist/LoginForm.d.ts +11 -2
  18. package/dist/LoginForm.d.ts.map +1 -1
  19. package/dist/LoginForm.js +5 -6
  20. package/dist/PreviewBanner.js +1 -1
  21. package/dist/RegisterForm.d.ts +22 -3
  22. package/dist/RegisterForm.d.ts.map +1 -1
  23. package/dist/RegisterForm.js +6 -7
  24. package/dist/SocialSignInButtons.d.ts +9 -2
  25. package/dist/SocialSignInButtons.d.ts.map +1 -1
  26. package/dist/SocialSignInButtons.js +5 -5
  27. package/dist/UserMenu.d.ts +1 -1
  28. package/dist/UserMenu.js +3 -3
  29. package/dist/createAuthClient.d.ts +1 -1
  30. package/dist/createAuthClient.d.ts.map +1 -1
  31. package/dist/createAuthClient.js +42 -4
  32. package/dist/createAuthenticatedFetch.d.ts +9 -9
  33. package/dist/createAuthenticatedFetch.d.ts.map +1 -1
  34. package/dist/createAuthenticatedFetch.js +50 -38
  35. package/dist/index.d.ts +21 -19
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +34 -17
  38. package/dist/invitation-status.d.ts +59 -0
  39. package/dist/invitation-status.d.ts.map +1 -0
  40. package/dist/invitation-status.js +32 -0
  41. package/dist/types.d.ts +25 -5
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/useAuth.d.ts +1 -1
  44. package/dist/useAuth.d.ts.map +1 -1
  45. package/dist/useAuth.js +5 -1
  46. package/dist/useWorkspaceAdminStatus.d.ts +134 -0
  47. package/dist/useWorkspaceAdminStatus.d.ts.map +1 -0
  48. package/dist/useWorkspaceAdminStatus.js +208 -0
  49. package/package.json +6 -7
  50. package/dist/useIsWorkspaceAdmin.d.ts +0 -21
  51. package/dist/useIsWorkspaceAdmin.d.ts.map +0 -1
  52. 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
- }