@edgedev/firebase 2.0.5 → 2.0.7

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/edgeFirebase.ts CHANGED
@@ -400,9 +400,14 @@ export const EdgeFirebase = class {
400
400
  this.unsubscibe['collection-data'] = unsubscribe
401
401
  }
402
402
 
403
-
403
+ private ruleHelperReset = async (): Promise<void> => {
404
+ const initRoleHelper = { uid: this.user.uid, 'edge-assignment-helper': {permissionType: "roles"} }
405
+ this.state.ruleHelpers['edge-assignment-helper'] = {permissionType: "roles"}
406
+ await setDoc(doc(this.db, "rule-helpers", this.user.uid), initRoleHelper);
407
+ }
404
408
 
405
409
  private startUserMetaSync = async (docSnap): Promise<void> => {
410
+ await this.ruleHelperReset();
406
411
  await this.startCollectionPermissionsSync()
407
412
  await this.initUserMetaPermissions(docSnap);
408
413
  this.user.loggedIn = true;
@@ -977,7 +982,12 @@ export const EdgeFirebase = class {
977
982
  }
978
983
  let index = collection.length;
979
984
  const ruleCheck: RuleCheck = { permissionType: "", permissionCheckPath: "", fullPath: collectionPath.replaceAll("/", "-"), action };
980
-
985
+ if (this.state.ruleHelpers[ruleKey]) {
986
+ const existingRuleHelper = this.state.ruleHelpers[ruleKey];
987
+ if (existingRuleHelper.fullPath === ruleCheck.fullPath && existingRuleHelper.action === ruleCheck.action) {
988
+ return;
989
+ }
990
+ }
981
991
  while (index > 0) {
982
992
  const collectionArray = JSON.parse(JSON.stringify(collection));
983
993
  const permissionCheck = collectionArray.splice(0, index).join("-");
@@ -1017,6 +1027,7 @@ export const EdgeFirebase = class {
1017
1027
  }
1018
1028
  const check = {[ruleKey]: ruleCheck, uid: this.user.uid };
1019
1029
  await setDoc(doc(this.db, "rule-helpers", this.user.uid), check, { merge: true });
1030
+ this.state.ruleHelpers[ruleKey] = ruleCheck;
1020
1031
  }
1021
1032
 
1022
1033
  public permissionCheckOnly = (action: action, collectionPath: string): boolean => {
@@ -1240,6 +1251,7 @@ export const EdgeFirebase = class {
1240
1251
  users: {},
1241
1252
  registrationCode: "",
1242
1253
  registrationMeta: {},
1254
+ ruleHelpers: {},
1243
1255
  });
1244
1256
 
1245
1257
  public getDocData = async (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 plugin for firebase authentication and firestore.",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -1,3 +1,7 @@
1
+ // TODO: THE permissionCheck will call a cloud function that will check the user's permissions also...
2
+ // This could function will right to "rules-helpers" collction a document with the user's uid and the collection path and the permission
3
+ // This will make the rules far more efficient and will allow for more complex rules // this only needs done really for snapshots...
4
+ // All the other document reads and writes should be made using a cloud functions exclusively and the cloud function will check the permissions
1
5
  const { onCall, HttpsError, logger, getFirestore, functions, admin, twilio, db } = require('./config.js')
2
6
 
3
7
  const authToken = process.env.TWILIO_AUTH_TOKEN
@@ -278,9 +282,9 @@ function setUser(userRef, newData, oldData, stagedDocId) {
278
282
  let userUpdate = { meta: newData.meta, stagedDocId }
279
283
 
280
284
  if (newData.meta && newData.meta.name) {
281
- const publicUserRef = db.collection('public-users').doc(newData.userId)
285
+ const publicUserRef = db.collection('public-users').doc(newData.uid)
282
286
  const publicMeta = { name: newData.meta.name }
283
- publicUserRef.set({ uid: newData.uid, meta: publicMeta, collectionPaths: newData.collectionPaths, userId: newData.userId })
287
+ publicUserRef.set({ uid: newData.uid, meta: publicMeta, collectionPaths: newData.collectionPaths, userId: newData.uid })
284
288
  }
285
289
 
286
290
  if (Object.prototype.hasOwnProperty.call(newData, 'roles')) {