-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfirebase.js
75 lines (64 loc) · 1.64 KB
/
firebase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Import the functions you need from the SDKs you need
import firebase from "firebase";
import "firebase/firestore";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBRXTIHWCzvbpfNoxb_ZDSV8ODV5qWfuQc",
authDomain: "petsmart-crescendo.firebaseapp.com",
projectId: "petsmart-crescendo",
storageBucket: "petsmart-crescendo.appspot.com",
messagingSenderId: "415842628991",
appId: "1:415842628991:web:492dc3efba618a2989164a"
};
// Initialize Firebase
let app;
if(firebase.apps.length === 0)
{
app = firebase.initializeApp(firebaseConfig);
}
else
{
app = firebase.app();
}
const auth = firebase.auth();
const db = firebase.firestore();
const createUserDocument = async (user,additionalData) => {
if(!user) return;
const userRef = db.doc(`users/${user.uid}`);
const snapshot = await userRef.get();
if(!snapshot.exists){
try{
userRef.set(additionalData);
}
catch(error){
console.log(error);
}
}
}
const strayRef = db.collection("Strays");
const addStrays = async (newStray) => {
try{
strayRef.add(newStray);
}
catch(error){
console.log(error);
}
};
const getStrays = () =>{
strayRef.get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
console.log(doc.data());
});
});
}
export {auth};
export {createUserDocument};
export {app};
export {addStrays};
export {strayRef};
export {getStrays};
export {db};
//const app = initializeApp(firebaseConfig);