@edgedev/firebase 1.9.16 → 1.9.18

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.
Files changed (2) hide show
  1. package/edgeFirebase.ts +57 -22
  2. package/package.json +1 -1
package/edgeFirebase.ts CHANGED
@@ -246,10 +246,6 @@ export const EdgeFirebase = class {
246
246
 
247
247
  private functions = null;
248
248
 
249
- public createRecaptchaVerifier = (containerId, parameters = { size: 'invisible' }) => {
250
- return new RecaptchaVerifier(containerId, parameters, this.auth);
251
- }
252
-
253
249
  public runFunction = async (functionName: string, data: Record<string, unknown>) => {
254
250
  data.uid = this.user.uid;
255
251
  const callable = httpsCallable(this.functions, functionName);
@@ -422,6 +418,8 @@ export const EdgeFirebase = class {
422
418
 
423
419
  private setOnAuthStateChanged = (): void => {
424
420
  onAuthStateChanged(this.auth, (userAuth) => {
421
+ const oldDiv = document.getElementById("recaptcha-container");
422
+ if (oldDiv) oldDiv.remove();
425
423
  if (userAuth) {
426
424
  this.user.loggingIn = true;
427
425
  this.user.email = userAuth.email;
@@ -444,7 +442,10 @@ export const EdgeFirebase = class {
444
442
  };
445
443
 
446
444
  public logInWithPhone = async (confirmationResult: ConfirmationResult, phoneCode: string): Promise<void> => {
445
+ const oldDiv = document.getElementById("recaptcha-container");
446
+ if (oldDiv) oldDiv.remove();
447
447
  try {
448
+ console.log(confirmationResult)
448
449
  const result = await confirmationResult.confirm(phoneCode);
449
450
  if (!Object.prototype.hasOwnProperty.call(result, "user")) {
450
451
  this.user.logInError = true;
@@ -459,11 +460,13 @@ export const EdgeFirebase = class {
459
460
  this.user.logInError = true;
460
461
  this.user.logInErrorMessage = "User does not exist";
461
462
  this.logOut();
463
+ return;
462
464
  }
463
465
  } catch (error) {
464
466
  this.user.logInError = true;
465
467
  this.user.logInErrorMessage = error.message;
466
468
  this.logOut();
469
+ return;
467
470
  }
468
471
  };
469
472
 
@@ -533,6 +536,9 @@ export const EdgeFirebase = class {
533
536
  }
534
537
 
535
538
  public sendPhoneCode = async (phone: string): Promise<any> => {
539
+ const oldDiv = document.getElementById("recaptcha-container");
540
+ if (oldDiv) oldDiv.remove();
541
+
536
542
  const newDiv = document.createElement("div");
537
543
  newDiv.setAttribute("id", "recaptcha-container");
538
544
  document.body.appendChild(newDiv);
@@ -548,7 +554,10 @@ export const EdgeFirebase = class {
548
554
  const confirmationResult = await signInWithPhoneNumber(this.auth, phone, recaptchaVerifier);
549
555
  return confirmationResult
550
556
  } catch (error) {
551
- return error
557
+ this.user.logInError = true;
558
+ this.user.logInErrorMessage = error.message;
559
+ this.logOut();
560
+ return false;
552
561
  }
553
562
  }
554
563
 
@@ -600,7 +609,8 @@ export const EdgeFirebase = class {
600
609
  } else if (authProvider === "microsoft") {
601
610
  response = await this.registerUserWithMicrosoft(providerScopes);
602
611
  } else if (authProvider === "phone") {
603
- // Try to sign in with the code
612
+ const oldDiv = document.getElementById("recaptcha-container");
613
+ if (oldDiv) oldDiv.remove();
604
614
  try {
605
615
  response = await userRegister.confirmationResult.confirm(userRegister.phoneCode);
606
616
  } catch (error) {
@@ -1381,28 +1391,52 @@ export const EdgeFirebase = class {
1381
1391
  collectionPath: string,
1382
1392
  docId: string
1383
1393
  ): Promise<actionResponse> => {
1384
- // console.log(collectionPath)
1385
- // console.log(docId)
1386
1394
  const canRead = await this.permissionCheck("read", collectionPath + '/' + docId);
1387
1395
  this.data[collectionPath + '/' + docId] = {};
1388
1396
  this.stopSnapshot(collectionPath + '/' + docId);
1389
1397
  this.unsubscibe[collectionPath + '/' + docId] = null;
1390
1398
  if (canRead) {
1391
1399
  const docRef = doc(this.db, collectionPath, docId);
1392
- const unsubscribe = onSnapshot(docRef, (doc) => {
1393
- if (doc.exists()) {
1394
- const item = doc.data();
1395
- item.docId = doc.id;
1396
- this.data[collectionPath + '/' + docId] = item;
1397
- } else {
1398
- this.data[collectionPath + '/' + docId] = {};
1399
- }
1400
- });
1401
- this.unsubscibe[collectionPath + '/' + docId] = unsubscribe;
1402
- return this.sendResponse({
1403
- success: true,
1404
- message: "line 1336",
1405
- meta: {}
1400
+
1401
+ return new Promise<actionResponse>((resolve, reject) => {
1402
+ let firstRun = true;
1403
+ const unsubscribe = onSnapshot(docRef, (doc) => {
1404
+ if (doc.exists()) {
1405
+ const item = doc.data();
1406
+ item.docId = doc.id;
1407
+ this.data[collectionPath + '/' + docId] = item;
1408
+
1409
+ // Only resolve the Promise on first run of onSnapshot if document exists
1410
+ if(firstRun) {
1411
+ firstRun = false;
1412
+ resolve(this.sendResponse({
1413
+ success: true,
1414
+ message: "startDocumentSnapshot " + collectionPath + '/' + docId,
1415
+ meta: {}
1416
+ }));
1417
+ }
1418
+ } else {
1419
+ this.data[collectionPath + '/' + docId] = {};
1420
+
1421
+ // Resolve the Promise with failure response if no document exists
1422
+ if(firstRun) {
1423
+ firstRun = false;
1424
+ resolve(this.sendResponse({
1425
+ success: false,
1426
+ message: `No document found in "${collectionPath}/${docId}"`,
1427
+ meta: {}
1428
+ }));
1429
+ }
1430
+ }
1431
+ }, (error) => {
1432
+ // Reject the Promise with the error response
1433
+ reject(this.sendResponse({
1434
+ success: false,
1435
+ message: `Error fetching document from "${collectionPath}/${docId}": ${error.message}`,
1436
+ meta: {}
1437
+ }));
1438
+ });
1439
+ this.unsubscibe[collectionPath + '/' + docId] = unsubscribe;
1406
1440
  });
1407
1441
  } else {
1408
1442
  return this.sendResponse({
@@ -1413,6 +1447,7 @@ export const EdgeFirebase = class {
1413
1447
  }
1414
1448
  };
1415
1449
 
1450
+
1416
1451
  public startSnapshot = async (
1417
1452
  collectionPath: string,
1418
1453
  queryList: FirestoreQuery[] = [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.9.16",
3
+ "version": "1.9.18",
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": {