-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFire.js
50 lines (41 loc) · 1.13 KB
/
Fire.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
import firebase from 'firebase';
import 'firebase/firestore';
import * as Analytics from 'expo-firebase-analytics';
import * as app from './app.json';
class Fire {
constructor() {
firebase.initializeApp(app.expo.web.config.firebase);
this.observeAuth();
}
observeAuth = () => {
firebase.auth().onAuthStateChanged(this.onAuthStateChanged);
}
onAuthStateChanged = user => {
if (!user) {
try {
firebase.auth().signInAnonymously();
} catch ({ message }) {
console.log(message);
}
}
}
// Used for firestore
getCollection = (collection) => {
return firebase.firestore().collection(collection);
}
// Used for realtime database
getRef = (reference) => {
return firebase.database().ref(reference);
}
off() {
this.ref.off();
}
async logEvent(eventName, properties) {
await Analytics.logEvent(eventName, properties);
}
async logScreen(screenName) {
await Analytics.setCurrentScreen(screenName);
}
}
Fire.db = new Fire();
export default Fire;