@edgedev/firebase 1.9.1 → 1.9.2

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
@@ -532,6 +532,7 @@ interface UserDataObject {
532
532
  firebaseUser: object; // contains the entire auth from firebase
533
533
  oAuthCredential: object; // contains oAuth ID and token information
534
534
  loggedIn: boolean;
535
+ loggingIn: boolean: // true while logging in used for loading screens
535
536
  logInError: boolean;
536
537
  logInErrorMessage: string;
537
538
  meta: object;
@@ -559,6 +560,8 @@ interface permissions {
559
560
  ```
560
561
  The reactive item **edgeFirebase.user.loggedIn** can be used in code or templates to determine if the user is logged in.
561
562
 
563
+ **edgeFirebase.user.logginIn** is true while the user is logging in. This can be used to show a loading screen.
564
+
562
565
  If there is an error logging in, **edgeFirebase.user.logInError** will be true and **edgeFirebase.user.logInErrorMessage** can be used to return that error to the user.
563
566
 
564
567
  After logging in, **edgeFirebase.logOut** becomes available. Logging out will also automatically disconnect all FireStore listeners.
package/edgeFirebase.ts CHANGED
@@ -103,6 +103,7 @@ interface UserDataObject {
103
103
  firebaseUser: object;
104
104
  oAuthCredential: { accessToken: string; idToken: string;}
105
105
  loggedIn: boolean;
106
+ loggingIn: boolean;
106
107
  logInError: boolean;
107
108
  logInErrorMessage: string;
108
109
  meta: object;
@@ -388,6 +389,7 @@ export const EdgeFirebase = class {
388
389
  await this.startCollectionPermissionsSync()
389
390
  await this.initUserMetaPermissions(docSnap);
390
391
  this.user.loggedIn = true;
392
+ this.user.loggingIn = false;
391
393
  };
392
394
 
393
395
  private waitForUser = async(): Promise<void> => {
@@ -406,6 +408,7 @@ export const EdgeFirebase = class {
406
408
  private setOnAuthStateChanged = (): void => {
407
409
  onAuthStateChanged(this.auth, (userAuth) => {
408
410
  if (userAuth) {
411
+ this.user.loggingIn = true;
409
412
  this.user.email = userAuth.email;
410
413
  this.user.uid = userAuth.uid;
411
414
  this.user.firebaseUser = userAuth;
@@ -420,6 +423,7 @@ export const EdgeFirebase = class {
420
423
  this.user.oAuthCredential.accessToken = "";
421
424
  this.user.oAuthCredential.idToken = "";
422
425
  this.user.loggedIn = false;
426
+ this.user.loggingIn = false;
423
427
  }
424
428
  });
425
429
  };
@@ -559,6 +563,7 @@ export const EdgeFirebase = class {
559
563
  }
560
564
  const initRoleHelper = {uid: response.user.uid}
561
565
  initRoleHelper["edge-assignment-helper"] = {permissionType: "roles"}
566
+ this.user.loggingIn = true;
562
567
  await setDoc(doc(this.db, "rule-helpers", response.user.uid), initRoleHelper);
563
568
  await updateDoc(doc(this.db, "staged-users/" + userRegister.registrationCode), stagedUserUpdate)
564
569
  this.logAnalyticsEvent("sign_up", { uid: response.user.uid});
@@ -986,6 +991,7 @@ export const EdgeFirebase = class {
986
991
  this.user.oAuthCredential.idToken = "";
987
992
  this.user.email = "";
988
993
  this.user.loggedIn = false;
994
+ this.user.loggingIn = false;
989
995
  this.user.meta = {};
990
996
  this.user.roles = [];
991
997
  this.user.specialPermissions = [];
@@ -1011,6 +1017,7 @@ export const EdgeFirebase = class {
1011
1017
  this.user.oAuthCredential.idToken = "";
1012
1018
  this.user.loggedIn = false;
1013
1019
  this.user.logInError = true;
1020
+ this.user.loggingIn = false;
1014
1021
  this.user.logInErrorMessage = error.code + ": " + error.message;
1015
1022
  });
1016
1023
  };
@@ -1032,6 +1039,7 @@ export const EdgeFirebase = class {
1032
1039
  public user: UserDataObject = reactive({
1033
1040
  uid: null,
1034
1041
  email: "",
1042
+ loggingIn: false,
1035
1043
  loggedIn: false,
1036
1044
  logInError: false,
1037
1045
  logInErrorMessage: "",
@@ -1327,7 +1335,7 @@ export const EdgeFirebase = class {
1327
1335
  }
1328
1336
  };
1329
1337
 
1330
- public startSnapshot = async(
1338
+ public startSnapshot = async (
1331
1339
  collectionPath: string,
1332
1340
  queryList: FirestoreQuery[] = [],
1333
1341
  orderList: FirestoreOrderBy[] = [],
@@ -1339,20 +1347,32 @@ export const EdgeFirebase = class {
1339
1347
  this.unsubscibe[collectionPath] = null;
1340
1348
  if (canRead) {
1341
1349
  const q = this.getQuery(collectionPath, queryList, orderList, max);
1342
- const unsubscribe = onSnapshot(q, (querySnapshot) => {
1343
- const items = {};
1344
- querySnapshot.forEach((doc) => {
1345
- const item = doc.data();
1346
- item.docId = doc.id;
1347
- items[doc.id] = item;
1350
+
1351
+ return new Promise<actionResponse>((resolve, reject) => {
1352
+ const unsubscribe = onSnapshot(q, (querySnapshot) => {
1353
+ const items = {};
1354
+ querySnapshot.forEach((doc) => {
1355
+ const item = doc.data();
1356
+ item.docId = doc.id;
1357
+ items[doc.id] = item;
1358
+ });
1359
+ this.data[collectionPath] = items;
1360
+ this.unsubscibe[collectionPath] = unsubscribe;
1361
+
1362
+ // Resolve the Promise with the success response
1363
+ resolve(this.sendResponse({
1364
+ success: true,
1365
+ message: "",
1366
+ meta: {}
1367
+ }));
1368
+ }, (error) => {
1369
+ // Reject the Promise with the error response
1370
+ reject(this.sendResponse({
1371
+ success: false,
1372
+ message: `Error fetching data from "${collectionPath}": ${error.message}`,
1373
+ meta: {}
1374
+ }));
1348
1375
  });
1349
- this.data[collectionPath] = items;
1350
- });
1351
- this.unsubscibe[collectionPath] = unsubscribe;
1352
- return this.sendResponse({
1353
- success: true,
1354
- message: "",
1355
- meta: {}
1356
1376
  });
1357
1377
  } else {
1358
1378
  return this.sendResponse({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
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": {