-
Notifications
You must be signed in to change notification settings - Fork 1
/
Auth.js
38 lines (34 loc) · 1.22 KB
/
Auth.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
class Auth {
static isLoggedIn = false;
static favBtn = document.getElementById('favBtn');
static signBtn = document.getElementById('signBtn')
static getUser() {
return new Promise((resolve, reject) =>
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
Auth.favBtn.classList.remove('d-none')
Auth.signBtn.innerHTML = ' <a class="nav-link" href="#">sign out</a>'
Auth.isLoggedIn = true;
return resolve(user);
} else {
Auth.signBtn.innerHTML = ' <a class="nav-link" href="#">sign in/up</a>'
Auth.isLoggedIn = false;
return resolve(null);
}
})
);
}
static async directToFirebase() {
const provider = new firebase.auth.GoogleAuthProvider();
const result = await firebase.auth().signInWithPopup(provider);
window.location.reload()
return result;
}
static signOut() {
firebase.auth().signOut()
.then(() => {
window.location.reload()
Auth.favBtn.classList.add('d-none')
})
}
}