-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathFirebase.js
More file actions
49 lines (40 loc) · 969 Bytes
/
Firebase.js
File metadata and controls
49 lines (40 loc) · 969 Bytes
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
import * as firebase from "firebase";
import * as firestore from "firebase/firestore";
export class Firebase {
constructor() {
this.init();
}
init() {
if (!window._initializedFirebase) {
firebase.initializeApp({
// usas crendencias do firebase
});
firebase.firestore().settings({
timestampsInSnapshots: true,
});
window._initializedFirebase = true;
}
}
initAuth() {
return new Promise((resolve, reject) => {
let provider = new firebase.auth.GoogleAuthProvider();
firebase
.auth()
.signInWithPopup(provider)
.then(function (result) {
let token = result.credential.accessToken;
let user = result.user;
resolve(user, token);
})
.catch(function (error) {
reject(error);
});
});
}
static db() {
return firebase.firestore();
}
static hd() {
return firebase.storage();
}
}