-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (49 loc) · 1.83 KB
/
Copy pathapp.js
File metadata and controls
56 lines (49 loc) · 1.83 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
import { auth, onAuthStateChanged, signOut, sendEmailVerification } from "./firebase.js";
let name = document.getElementById("name");
let email = document.getElementById("email");
let profileContent = document.getElementById("profile-content");
let spinner = document.getElementById("spinner");
onAuthStateChanged(auth, (user) => {
if (user) {
sendEmailVerification(auth.currentUser)
.then(() => {
// Email verification sent!
// ...
console.log("email sent");
});
const uid = user.uid;
if (location.pathname !== "/profile.html") {
window.location = "/profile.html";
}
spinner.style.display = "none";
profileContent.style.display = "flex";
console.log("User Login uid---->", user, uid);
email.innerHTML = user.email;
name.innerHTML = user.email.slice(0, user.email.indexOf("@"));
} else {
// User is signed out
if (location.pathname !== "/register.html" && location.pathname !== "/index.html") {
window.location = "/index.html";
}
console.log("User Logged out!");
}
});
let logoutUser = () => {
signOut(auth).then(() => {
console.log("Logged Out Successfully!")
// alert("Logged Out Successfully!");
window.location.href = "index.html";
}).catch((error) => {
// An error happened.
console.log("Unable to LogOut!", error)
});
}
let logout = document.getElementById("logout");
logout && logout.addEventListener('click', logoutUser); //alternate of if statement
// if(logout){
// logout.addEventListener('click', logoutUser);
// }
//to resolve addEventListener add below if statement OR create separate files
// if (registerUser) {
// registerUser.addEventListener("click", registerFunction);
// }