-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (49 loc) · 1.77 KB
/
script.js
File metadata and controls
55 lines (49 loc) · 1.77 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
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.14.0/firebase-app.js";
import {
getAuth,
signInWithEmailAndPassword,
} from 'https://www.gstatic.com/firebasejs/9.14.0/firebase-auth.js';
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const email = document.getElementById('email');
const password = document.getElementById('password');
const passwordVisiblility = document.querySelector('.passwordVisiblility');
const visibility = document.querySelector('.visibility');
const loginBtn = document.querySelector('.loginBtn');
const loginForm = document.getElementById('login-form');
const pkg = {
isVisible: false,
};
passwordVisiblility.addEventListener('click', (e) => {
e.preventDefault();
if (pkg.isVisible) {
pkg.isVisible = false;
password.type = 'password';
visibility.classList.add('fa-eye');
visibility.classList.remove('fa-eye-slash');
} else {
password.type = 'text';
pkg.isVisible = true;
visibility.classList.remove('fa-eye');
visibility.classList.add('fa-eye-slash');
}
});
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
console.log('Login Clicked');
signInWithEmailAndPassword(auth, email.value, password.value)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
console.log(user);
window.location.href = './Assets/AfterLoginChapert/index_afterLogin.html';
// ...
})
.catch((err) => {
if (err.code === 'auth/wrong-password') {
alert('Wrong Email/Password');
} else if (err.code === 'auth/user-not-found') {
alert('User Not Found...');
}
});
});