-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
50 lines (44 loc) · 1.36 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
39
40
41
42
43
44
45
46
47
48
49
50
// listen for auth status changes
auth.onAuthStateChanged((user) =>{
if(user){
db.collection('guides').get().then(snapshot=>{
setupGuides(snapshot.docs);
setupUi(user);
});
} else {
setupUi([]);
setupGuides([]);
}
});
// signup
var signupForm = document.querySelector('#signup-form');
signupForm.addEventListener('submit',(e)=>{
e.preventDefault();
// get user info
var email = signupForm['signup-email'].value;
var password = signupForm['signup-password'].value;
// sign up the user
auth.createUserWithEmailAndPassword(email,password).then(cred =>{
var modal = document.querySelector('#modal-signup');
M.Modal.getInstance(modal).close();
signupForm.reset();
});
});
// logout
const logout = document.querySelector('#logout');
logout.addEventListener('click',(e)=>{
e.preventDefault();
auth.signOut();
});
// login
const loginForm = document.querySelector('#login-form');
loginForm.addEventListener('submit',(e)=>{
e.preventDefault();
const email = loginForm['login-email'].value;
const password = loginForm['login-password'].value;
auth.signInWithEmailAndPassword(email,password).then((cred)=>{
var modal = document.querySelector('#modal-login');
M.Modal.getInstance(modal).close();
loginForm.reset();
});
});