-
Notifications
You must be signed in to change notification settings - Fork 1
/
firebase.js
47 lines (37 loc) · 1.21 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
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";
import { ref, onUnmounted } from "vue";
const firebaseConfig = {
apiKey: "AIzaSyBU7nqA_8l1xmdpebeY0cJ90KobpOwZ3gE",
authDomain: "lowkey-2d7de.firebaseapp.com",
projectId: "lowkey-2d7de",
storageBucket: "lowkey-2d7de.appspot.com",
messagingSenderId: "525918258962",
appId: "1:525918258962:web:235f2406bef8608a9615cb",
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
const db = firebaseApp.firestore();
const usersCollection = db.collection("passwords");
export const createUser = (user) => {
return usersCollection.add(user);
};
export const getUser = async (id) => {
const user = await usersCollection.doc(id).get();
return user.exists ? user.data() : null;
};
export const updateUser = (id, user) => {
return usersCollection.doc(id).update(user);
};
export const deleteUser = (id) => {
return usersCollection.doc(id).delete();
};
export const useLoadUsers = () => {
const users = ref([]);
const close = usersCollection.onSnapshot((snapshot) => {
users.value = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() }));
});
onUnmounted(close);
return users;
};
export default firebase;