-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
69 lines (50 loc) · 1.8 KB
/
auth.js
File metadata and controls
69 lines (50 loc) · 1.8 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// refs for main section based on login/out
const loggedIn = document.querySelectorAll('.logged-in');
const loggedOut = document.querySelectorAll('.logged-out');
///////////////// SIGNUP
// get reference to signup form
const signupForm = document.querySelector('#signup-form');
// Add event listener to submit form
signupForm.addEventListener('submit', event => {
event.preventDefault();
const email = signupForm['signup-email'].value;
const password = signupForm['signup-password'].value;
// Create user (auth)
auth.createUserWithEmailAndPassword(email, password)
.then(cred => {
// Form disappears
document.querySelector('.modal.signup').style.display = 'none';
// Clear input fields
signupForm.reset();
});
// Background opacity back to 1
document.querySelector('#content').style.opacity = 1;
});
///////////////// LOGIN
// get reference to login form
const loginForm = document.querySelector('#login-form');
// event listener to login submit
loginForm.addEventListener('submit', event => {
event.preventDefault();
const email = loginForm['login-email'].value;
const password = loginForm['login-password'].value;
auth.signInWithEmailAndPassword(email, password).then(cred => {
// Form disappears
document.querySelector('.modal.login').style.display = 'none';
// Clear input fields
loginForm.reset();
});
// Background opacity back to 1
document.querySelector('#content').style.opacity = 1;
// Call user to click on button to display all contacts
setInterval(() => {
displayContactBtn.classList.toggle('green');
}, 500)
});
///////////////// LOGOUT
const logout = document.querySelector('#logout__btn');
logout.addEventListener('click', event => {
event.preventDefault();
// sign out method using auth object
auth.signOut();
});