-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (58 loc) · 2.1 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
firebase.auth().onAuthStateChanged(firebaseUser => {
const hideLogout = document.getElementById('hideLogout');
const btnReunite = document.getElementsByClassName('btnReunite');
if(firebaseUser){
/*BEGIN USER GREETING*/
const userPicElement = document.getElementById('user-pic');
const userNameElement = document.getElementById('user-name');
// Returns the signed-in user's profile Pic URL.
function getProfilePicURL(){
return firebase.auth().currentUser.photoURL || '/assets/images/profile_placeholder.png';
}
// Returns the signed-in user's display name.
function getUserName() {
return firebase.auth().currentUser.displayName;
}
// Get the signed-in user's profile pic and name.
var profilePicUrl = getProfilePicURL();
var userName = getUserName();
// Set the user's profile pic and name.
userPicElement.innerHTML = `<img src='${profilePicUrl}' id="user-pic">`;
if(userName === null){
userNameElement.innerHTML = `<b>Welcome, User</b>`;
}
else{
userNameElement.innerHTML = `<b>Welcome, ${userName}</b>`;
}
/*END USER GREETING*/
hideLogout.classList.remove('hide');
const btnLogout = document.getElementById('btnLogout');
btnLogout.addEventListener('click', e=> {
swal({
icon: "warning",
title: "Are You Sure?",
buttons: ["Back", "Log Out!"],
dangerMode: true,
closeOnClickOutside: false})
.then((willDelete) => {
if(willDelete){
firebase.auth().signOut();
window.location="index.html";
}
else{
}
});
});
for(var i=0; i<btnReunite.length; i++){
btnReunite[i].addEventListener('click', e=> {
window.location="page1.html";
});}
}
else{
hideLogout.classList.add('hide');
for(var i=0; i<btnReunite.length; i++){
btnReunite[i].addEventListener('click', e=> {
window.location="login.html";
});}
}
});