Skip to content

Commit

Permalink
Merge pull request #47 from CudoVentures/CUDOS-1752-catch-firebase-er…
Browse files Browse the repository at this point in the history
…rors

CUDOS-1752 catch firebase errors as they may contain sensitive info
  • Loading branch information
tgntr authored Oct 31, 2022
2 parents c7e854d + 89bbffa commit 2603fba
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/utils/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { FIREBASE_API_KEY, FIREBASE_AUTH_DOMAIN, FIREBASE_AUTH_EMAIL, FIREBASE_AUTH_PASSWORD, FIREBASE_COLLECTION_NAME, FIREBASE_PROJECT_ID } from "./constants";
import { initializeApp } from 'firebase/app';
import { getAuth,signInWithEmailAndPassword } from 'firebase/auth';
import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';
import { getFirestore, Firestore, doc, getDoc, setDoc } from 'firebase/firestore/lite';
import { AddressBook } from "store/user";

export class Firebase {
static saveAddressBook = async (address: string, addressBook: AddressBook): Promise<void> => {
const db = await useFirestore();
const addressBookDoc = doc(db, FIREBASE_COLLECTION_NAME, address);
return setDoc(addressBookDoc, { addressBook });
try {
const db = await useFirestore();
const addressBookDoc = doc(db, FIREBASE_COLLECTION_NAME, address);
return setDoc(addressBookDoc, { addressBook });
} catch {
throw new Error("Error while saving address book to Firebase")
}
};

static getAddressBook = async (address: string): Promise<AddressBook> => {
const db = await useFirestore();
const addressBookDoc = await getDoc(doc(db, FIREBASE_COLLECTION_NAME, address));
return addressBookDoc.data()?.addressBook ?? {};
try {
const db = await useFirestore();
const addressBookDoc = await getDoc(doc(db, FIREBASE_COLLECTION_NAME, address));
return addressBookDoc.data()?.addressBook ?? {};
} catch {
throw new Error("Error while getting address book from Firebase")
}
};
}

Expand Down

0 comments on commit 2603fba

Please sign in to comment.