@firecms/user_management 3.0.0-canary.40 → 3.0.0-canary.41
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/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/{useBuildFirestoreUserManagement.d.ts → useFirestoreUserManagement.d.ts} +1 -1
- package/dist/index.es.js +385 -379
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -6
- package/src/hooks/index.ts +1 -1
- package/src/hooks/{useBuildFirestoreUserManagement.tsx → useFirestoreUserManagement.tsx} +33 -25
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
} from "firebase/firestore";
|
12
12
|
import { FirebaseApp } from "firebase/app";
|
13
13
|
import { UserManagement } from "../types";
|
14
|
-
import { Authenticator, PermissionsBuilder, Role, User
|
14
|
+
import { Authenticator, PermissionsBuilder, Role, User } from "@firecms/core";
|
15
15
|
import { resolveUserRolePermissions } from "../utils";
|
16
16
|
|
17
17
|
type UserWithRoleIds = User & { roles: string[] };
|
@@ -62,15 +62,15 @@ export interface UserManagementParams {
|
|
62
62
|
* @param usersLimit
|
63
63
|
* @param canEditRoles
|
64
64
|
*/
|
65
|
-
export function
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
65
|
+
export function useFirestoreUserManagement({
|
66
|
+
firebaseApp,
|
67
|
+
usersPath = "__FIRECMS/config/users",
|
68
|
+
rolesPath = "__FIRECMS/config/roles",
|
69
|
+
usersLimit,
|
70
|
+
canEditRoles = true,
|
71
|
+
allowDefaultRolesCreation,
|
72
|
+
includeCollectionConfigPermissions
|
73
|
+
}: UserManagementParams): UserManagement {
|
74
74
|
|
75
75
|
const [rolesLoading, setRolesLoading] = React.useState<boolean>(true);
|
76
76
|
const [usersLoading, setUsersLoading] = React.useState<boolean>(true);
|
@@ -87,6 +87,15 @@ export function useBuildFirestoreUserManagement({
|
|
87
87
|
|
88
88
|
const loading = rolesLoading || usersLoading;
|
89
89
|
|
90
|
+
console.log("loading", {
|
91
|
+
rolesLoading,
|
92
|
+
usersLoading,
|
93
|
+
roles,
|
94
|
+
usersWithRoleIds,
|
95
|
+
users
|
96
|
+
|
97
|
+
});
|
98
|
+
|
90
99
|
useEffect(() => {
|
91
100
|
if (!firebaseApp || !rolesPath) return;
|
92
101
|
const firestore = getFirestore(firebaseApp);
|
@@ -137,9 +146,9 @@ export function useBuildFirestoreUserManagement({
|
|
137
146
|
}, [firebaseApp, usersPath]);
|
138
147
|
|
139
148
|
const saveUser = useCallback(async (user: User): Promise<User> => {
|
140
|
-
if (!firebaseApp) throw Error("
|
149
|
+
if (!firebaseApp) throw Error("useFirestoreUserManagement Firebase not initialised");
|
141
150
|
const firestore = getFirestore(firebaseApp);
|
142
|
-
if (!firestore || !usersPath) throw Error("
|
151
|
+
if (!firestore || !usersPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
143
152
|
console.debug("Persisting user", user);
|
144
153
|
const roleIds = user.roles?.map(r => r.id);
|
145
154
|
const {
|
@@ -155,12 +164,12 @@ export function useBuildFirestoreUserManagement({
|
|
155
164
|
} else {
|
156
165
|
return addDoc(collection(firestore, usersPath), data).then(() => user);
|
157
166
|
}
|
158
|
-
}, [usersPath]);
|
167
|
+
}, [usersPath, firebaseApp]);
|
159
168
|
|
160
169
|
const saveRole = useCallback((role: Role): Promise<void> => {
|
161
|
-
if (!firebaseApp) throw Error("
|
170
|
+
if (!firebaseApp) throw Error("useFirestoreUserManagement Firebase not initialised");
|
162
171
|
const firestore = getFirestore(firebaseApp);
|
163
|
-
if (!firestore || !rolesPath) throw Error("
|
172
|
+
if (!firestore || !rolesPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
164
173
|
console.debug("Persisting role", role);
|
165
174
|
const {
|
166
175
|
id,
|
@@ -168,26 +177,26 @@ export function useBuildFirestoreUserManagement({
|
|
168
177
|
} = role;
|
169
178
|
const ref = doc(firestore, rolesPath, id);
|
170
179
|
return setDoc(ref, roleData, { merge: true });
|
171
|
-
}, [rolesPath]);
|
180
|
+
}, [rolesPath, firebaseApp]);
|
172
181
|
|
173
182
|
const deleteUser = useCallback(async (user: User): Promise<void> => {
|
174
|
-
if (!firebaseApp) throw Error("
|
183
|
+
if (!firebaseApp) throw Error("useFirestoreUserManagement Firebase not initialised");
|
175
184
|
const firestore = getFirestore(firebaseApp);
|
176
|
-
if (!firestore || !usersPath) throw Error("
|
185
|
+
if (!firestore || !usersPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
177
186
|
console.debug("Deleting", user);
|
178
187
|
const { uid } = user;
|
179
188
|
return deleteDoc(doc(firestore, usersPath, uid));
|
180
|
-
}, [usersPath]);
|
189
|
+
}, [usersPath, firebaseApp]);
|
181
190
|
|
182
191
|
const deleteRole = useCallback((role: Role): Promise<void> => {
|
183
|
-
if (!firebaseApp) throw Error("
|
192
|
+
if (!firebaseApp) throw Error("useFirestoreUserManagement Firebase not initialised");
|
184
193
|
const firestore = getFirestore(firebaseApp);
|
185
|
-
if (!firestore || !rolesPath) throw Error("
|
194
|
+
if (!firestore || !rolesPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
186
195
|
console.debug("Deleting", role);
|
187
196
|
const { id } = role;
|
188
197
|
const ref = doc(firestore, rolesPath, id);
|
189
198
|
return deleteDoc(ref);
|
190
|
-
}, [rolesPath]);
|
199
|
+
}, [rolesPath, firebaseApp]);
|
191
200
|
|
192
201
|
const collectionPermissions: PermissionsBuilder = useCallback(({
|
193
202
|
collection,
|
@@ -197,12 +206,11 @@ export function useBuildFirestoreUserManagement({
|
|
197
206
|
user
|
198
207
|
}), []);
|
199
208
|
|
200
|
-
const userIds = users.map(u => u.uid);
|
201
209
|
const defineRolesFor: ((user: User) => Role[] | undefined) = useCallback((user) => {
|
202
210
|
if (!users) throw Error("Users not loaded");
|
203
211
|
const mgmtUser = users.find(u => u.email?.toLowerCase() === user?.email?.toLowerCase());
|
204
212
|
return mgmtUser?.roles;
|
205
|
-
}, [
|
213
|
+
}, [users]);
|
206
214
|
|
207
215
|
const authenticator: Authenticator = useCallback(({ user }) => {
|
208
216
|
console.log("Authenticating user", user);
|
@@ -226,7 +234,7 @@ export function useBuildFirestoreUserManagement({
|
|
226
234
|
}
|
227
235
|
|
228
236
|
throw Error("Could not find a user with the provided email");
|
229
|
-
}, [loading,
|
237
|
+
}, [loading, users])
|
230
238
|
|
231
239
|
return {
|
232
240
|
loading,
|