@edgedev/firebase 1.4.2 → 1.4.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/README.md CHANGED
@@ -257,8 +257,8 @@ interface usersByEmail {
257
257
  ```typescript
258
258
  interface user {
259
259
  email: string;
260
- roles: {[collectionPath: string ]: "admin" | "user"}
261
- specialPermissions: {[collectionPath: string]: permissions};
260
+ roles: role[];
261
+ specialPermissions: specialPermission[];
262
262
  userId: string;
263
263
  docId: string;
264
264
  uid: string;
@@ -266,6 +266,29 @@ interface user {
266
266
  }
267
267
  ```
268
268
 
269
+ ```typescript
270
+ interface role {
271
+ collectionPath: "-" | string; // - is root
272
+ role: "admin" | "user";
273
+ }
274
+ ```
275
+
276
+ ```typescript
277
+ interface specialPermission {
278
+ collectionPath: "-" | string; // - is root
279
+ permissions: permissions;
280
+ }
281
+ ```
282
+
283
+ ```typescript
284
+ interface permissions {
285
+ assign: boolean;
286
+ read: boolean;
287
+ write: boolean;
288
+ delete: boolean;
289
+ }
290
+ ```
291
+
269
292
 
270
293
 
271
294
  ### List Collections with Assign Access
package/edgeFirebase.ts CHANGED
@@ -103,8 +103,8 @@ interface newUser {
103
103
 
104
104
  interface user {
105
105
  email: string;
106
- roles: {[collectionPath: string ]: "admin" | "user"}
107
- specialPermissions: {[collectionPath: string]: permissions};
106
+ roles: role[];
107
+ specialPermissions: specialPermission[];
108
108
  userId: string;
109
109
  docId: string;
110
110
  uid: string;
@@ -438,19 +438,28 @@ export const EdgeFirebase = class {
438
438
  newUser.specialPermissions
439
439
  );
440
440
  if (canAssignRole.canDo && canAssignSpecialPermissions.canDo) {
441
- const userMeta: userMeta = {
442
- docId: newUser.email,
443
- userId: "",
444
- email: newUser.email,
445
- roles: newUser.roles,
446
- specialPermissions: newUser.specialPermissions,
447
- meta: newUser.meta
448
- };
449
- this.generateUserMeta(userMeta);
450
- return this.sendResponse({
451
- success: true,
452
- message: ""
453
- });
441
+ const userRef = doc(this.db, "users", newUser.email);
442
+ const userSnap = await getDoc(userRef);
443
+ if (!userSnap.exists()) {
444
+ const userMeta: userMeta = {
445
+ docId: newUser.email,
446
+ userId: "",
447
+ email: newUser.email,
448
+ roles: newUser.roles,
449
+ specialPermissions: newUser.specialPermissions,
450
+ meta: newUser.meta
451
+ };
452
+ this.generateUserMeta(userMeta);
453
+ return this.sendResponse({
454
+ success: true,
455
+ message: ""
456
+ });
457
+ } else {
458
+ return this.sendResponse({
459
+ success: false,
460
+ message: "User already exists"
461
+ });
462
+ }
454
463
  } else {
455
464
  return this.sendResponse({
456
465
  success: false,
@@ -1064,15 +1073,15 @@ export const EdgeFirebase = class {
1064
1073
  userList[user.email] = {
1065
1074
  docId: user.docId,
1066
1075
  email: user.email,
1067
- roles: {[collectionPath]: user.roles[collectionPath].role },
1068
- specialPermissions: {},
1076
+ roles: [{collectionPath, role: user.roles[collectionPath].role }],
1077
+ specialPermissions: [],
1069
1078
  meta: user.meta,
1070
1079
  last_updated: user.last_updated,
1071
1080
  userId: user.userId,
1072
1081
  uid: user.uid
1073
1082
  }
1074
1083
  } else {
1075
- userList[user.email].roles[collectionPath] = user.roles[collectionPath].role
1084
+ userList[user.email].roles.push({ collectionPath, role: user.roles[collectionPath].role })
1076
1085
  }
1077
1086
  });
1078
1087
  const specialPermissionsUsers = await getDocs(
@@ -1091,15 +1100,15 @@ export const EdgeFirebase = class {
1091
1100
  userList[user.email] = {
1092
1101
  docId: user.docId,
1093
1102
  email: user.email,
1094
- role: {},
1095
- specialPermissions: {[collectionPath]: user.specialPermissions[collectionPath].permissions},
1103
+ role: [],
1104
+ specialPermissions: [{ collectionPath, permissions: user.specialPermissions[collectionPath].permissions }],
1096
1105
  meta: user.meta,
1097
1106
  last_updated: user.last_updated,
1098
1107
  userId: user.userId,
1099
1108
  uid: user.uid
1100
1109
  }
1101
1110
  } else {
1102
- userList[user.email].specialPermissions[collectionPath] = user.specialPermissions[collectionPath].permissions
1111
+ userList[user.email].specialPermissions.push({ collectionPath, permissions: user.specialPermissions[collectionPath].permissions })
1103
1112
  }
1104
1113
  });
1105
1114
  }
@@ -1186,7 +1195,7 @@ export const EdgeFirebase = class {
1186
1195
  }
1187
1196
  };
1188
1197
 
1189
- public storeUserRoles = async (
1198
+ private storeUserRoles = async (
1190
1199
  email: string,
1191
1200
  collectionPath: string,
1192
1201
  role: "admin" | "user"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 global composable for firebase authentication and firestore.",
5
5
  "main": "index.ts",
6
6
  "scripts": {