@edgedev/firebase 2.0.1 → 2.0.4

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
@@ -110,7 +110,7 @@ interface UserDataObject {
110
110
  firebaseUser: object;
111
111
  oAuthCredential: { accessToken: string; idToken: string;}
112
112
  loggedIn: boolean;
113
- loggingIn: boolean;
113
+ loggingIn: boolean | null;
114
114
  logInError: boolean;
115
115
  logInErrorMessage: string;
116
116
  meta: object;
@@ -424,6 +424,7 @@ export const EdgeFirebase = class {
424
424
 
425
425
  private setOnAuthStateChanged = (): void => {
426
426
  onAuthStateChanged(this.auth, (userAuth) => {
427
+ console.log('onAuthStateChanged')
427
428
  const oldDiv = document.getElementById("recaptcha-container");
428
429
  if (oldDiv) oldDiv.remove();
429
430
  if (userAuth) {
@@ -1222,7 +1223,7 @@ export const EdgeFirebase = class {
1222
1223
  public user: UserDataObject = reactive({
1223
1224
  uid: null,
1224
1225
  email: "",
1225
- loggingIn: false,
1226
+ loggingIn: null,
1226
1227
  loggedIn: false,
1227
1228
  logInError: false,
1228
1229
  logInErrorMessage: "",
@@ -1667,6 +1668,30 @@ export const EdgeFirebase = class {
1667
1668
  this.state.users = items;
1668
1669
  });
1669
1670
  this.unsubscibe["staged-users"] = unsubscibe;
1671
+ } else {
1672
+ const q = query(
1673
+ collection(this.db, "public-users"),
1674
+ where(
1675
+ "collectionPaths",
1676
+ "array-contains",
1677
+ collectionPath.replaceAll('/', '-')
1678
+ )
1679
+ )
1680
+ const unsubscibe = await onSnapshot(q, (querySnapshot) => {
1681
+ const items = {};
1682
+ querySnapshot.forEach((doc) => {
1683
+ const user = doc.data();
1684
+ const docId = doc.id;
1685
+ const item = {
1686
+ docId,
1687
+ meta: user.meta,
1688
+ userId: user.userId,
1689
+ }
1690
+ items[doc.id] = item;
1691
+ });
1692
+ this.state.users = items;
1693
+ });
1694
+ this.unsubscibe["staged-users"] = unsubscibe;
1670
1695
  }
1671
1696
  }
1672
1697
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "2.0.1",
3
+ "version": "2.0.4",
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": {
package/src/config.js CHANGED
@@ -4,12 +4,28 @@ const admin = require('firebase-admin')
4
4
  admin.initializeApp()
5
5
 
6
6
  const { onCall, HttpsError } = require('firebase-functions/v2/https')
7
+ const { onSchedule } = require('firebase-functions/v2/scheduler')
8
+ const {
9
+ onDocumentWritten,
10
+ onDocumentCreated,
11
+ onDocumentUpdated,
12
+ onDocumentDeleted,
13
+ Change,
14
+ FirestoreEvent,
15
+ } = require('firebase-functions/v2/firestore')
7
16
  const { logger } = require('firebase-functions/v2')
8
17
  const { getFirestore } = require('firebase-admin/firestore')
9
18
  const twilio = require('twilio')
10
19
  const db = getFirestore()
11
20
 
12
21
  module.exports = {
22
+ onSchedule,
23
+ onDocumentWritten,
24
+ onDocumentCreated,
25
+ onDocumentUpdated,
26
+ onDocumentDeleted,
27
+ Change,
28
+ FirestoreEvent,
13
29
  onCall,
14
30
  HttpsError,
15
31
  logger,
@@ -19,3 +35,4 @@ module.exports = {
19
35
  twilio,
20
36
  db,
21
37
  }
38
+
@@ -277,6 +277,12 @@ function setUser(userRef, newData, oldData, stagedDocId) {
277
277
  return userRef.get().then((user) => {
278
278
  let userUpdate = { meta: newData.meta, stagedDocId }
279
279
 
280
+ if (newData.meta && newData.meta.name) {
281
+ const publicUserRef = db.collection('public-users').doc(newData.userId)
282
+ const publicMeta = { name: newData.meta.name }
283
+ publicUserRef.set({ uid: newData.uid, meta: publicMeta, collectionPaths: newData.collectionPaths, userId: newData.userId })
284
+ }
285
+
280
286
  if (Object.prototype.hasOwnProperty.call(newData, 'roles')) {
281
287
  userUpdate = { ...userUpdate, roles: newData.roles }
282
288
  }
@@ -1,3 +1,4 @@
1
+ rules_version = '2';
1
2
  // #EDGE FIREBASE RULES START
2
3
  service cloud.firestore {
3
4
 
@@ -8,6 +9,14 @@ service cloud.firestore {
8
9
  allow delete: if false;
9
10
  }
10
11
 
12
+ match /databases/{database}/documents/public-users/{user} {
13
+ allow read: if true;
14
+ allow list: if true;
15
+ allow create: if false;
16
+ allow update: if false;
17
+ allow delete: if false;
18
+ }
19
+
11
20
  match /databases/{database}/documents/events/{event} {
12
21
  allow read: if false;
13
22
  allow create: if false;
@@ -228,7 +237,7 @@ service cloud.firestore {
228
237
  }
229
238
  function checkPermission(collectionPath, permissionCheck) {
230
239
  let user = get(/databases/$(database)/documents/users/$(request.auth.uid)).data;
231
- let skipPaths = ["collection-data", "users", "staged-users", "events", "rule-helpers"];
240
+ let skipPaths = ["collection-data", "users", "staged-users", "events", "rule-helpers", "phone-auth", "public-users"];
232
241
  let ruleHelper = get(/databases/$(database)/documents/rule-helpers/$(request.auth.uid)).data;
233
242
  return !(collectionPath in skipPaths) &&
234
243
  !(permissionCheck == "write" &&
@@ -303,4 +312,4 @@ service cloud.firestore {
303
312
  }
304
313
  }
305
314
  }
306
- // #EDGE FIREBASE RULES END
315
+ // #EDGE FIREBASE RULES END