@rebasepro/client-firebase 0.2.4 → 0.2.5

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.
@@ -1,4 +1,9 @@
1
- import { AuthController, DataDriver, Role, User, UserManagementDelegate } from "@rebasepro/types";
1
+ import { AuthController, DataDriver, User, UserManagementDelegate } from "@rebasepro/types";
2
+ export interface Role {
3
+ id: string;
4
+ name: string;
5
+ isAdmin?: boolean;
6
+ }
2
7
  export interface UserManagementDelegateParams<CONTROLLER extends AuthController<User> = AuthController<User>> {
3
8
  authController: CONTROLLER;
4
9
  /**
@@ -1,12 +1,12 @@
1
1
  import { FirebaseApp } from "@firebase/app";
2
2
  import { FirebaseAuthController, FirebaseSignInOption, FirebaseSignInProvider, FirebaseUserWrapper } from "../types";
3
- import { Role, User } from "@rebasepro/types";
3
+ import type { User } from "@rebasepro/types";
4
4
  export interface FirebaseAuthControllerProps {
5
5
  loading?: boolean;
6
6
  firebaseApp?: FirebaseApp;
7
7
  signInOptions?: Array<FirebaseSignInProvider | FirebaseSignInOption>;
8
8
  onSignOut?: () => void;
9
- defineRolesFor?: (user: User) => Promise<Role[] | undefined> | Role[] | undefined;
9
+ defineRolesFor?: (user: User) => Promise<string[] | undefined> | string[] | undefined;
10
10
  }
11
11
  /**
12
12
  * Use this hook to build an {@link AuthController} based on Firebase Auth
package/dist/index.es.js CHANGED
@@ -34,9 +34,7 @@ const useFirebaseAuthController = ({
34
34
  const [userRoles, _setUserRoles] = useState();
35
35
  const [extra, setExtra] = useState();
36
36
  const setUserRoles = useCallback((roles) => {
37
- const currentRoleIds = userRoles?.map((r) => r.id);
38
- const newRoleIds = roles?.map((r_0) => r_0.id);
39
- if (!deepEqual(currentRoleIds, newRoleIds)) {
37
+ if (!deepEqual(userRoles, roles)) {
40
38
  _setUserRoles(roles);
41
39
  }
42
40
  }, [userRoles]);
@@ -224,8 +222,7 @@ const useFirebaseAuthController = ({
224
222
  }, []);
225
223
  const firebaseUserWrapper = loggedUser ? {
226
224
  ...loggedUser,
227
- roles: userRoles?.map((r_1) => r_1.id),
228
- // User.roles is string[], keep Role[] internally only
225
+ roles: userRoles,
229
226
  firebaseUser: loggedUser
230
227
  } : null;
231
228
  return {
@@ -2024,8 +2021,8 @@ function useBuildUserManagement({
2024
2021
  if (!usersWithRoleIds) throw Error("Users not loaded");
2025
2022
  const mgmtUser = usersWithRoleIds.find((u_1) => u_1.email?.toLowerCase() === user_1?.email?.toLowerCase());
2026
2023
  if (!mgmtUser || !mgmtUser.roles) return void 0;
2027
- return roles.filter((r) => mgmtUser.roles.includes(r.id));
2028
- }, [roles, usersWithRoleIds]);
2024
+ return mgmtUser.roles;
2025
+ }, [usersWithRoleIds]);
2029
2026
  const accessGate = useCallback(({
2030
2027
  user: user_2
2031
2028
  }) => {
@@ -2065,8 +2062,8 @@ function useBuildUserManagement({
2065
2062
  throw Error("Could not find a user with the provided email in the user management system.");
2066
2063
  }, [loading, users]);
2067
2064
  const userRoles = authController.user ? defineRolesFor(authController.user) : void 0;
2068
- const isAdmin = (userRoles ?? []).some((r_0) => r_0.id === "admin");
2069
- const userRoleIds = userRoles?.map((r_1) => r_1.id);
2065
+ const isAdmin = (userRoles ?? []).some((r) => r === "admin");
2066
+ const userRoleIds = userRoles;
2070
2067
  useEffect(() => {
2071
2068
  console.debug("Setting user roles", {
2072
2069
  userRoles,