forked from jaysomani/firstspot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.js
52 lines (45 loc) · 1.68 KB
/
home.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
// Reference
const userlink = document.getElementById('user');
const signoutlink = document.getElementById('signOut');
const header = document.getElementById('hh');
let currentUser = null;
// Functions
function getUsername() {
currentUser = sessionStorage.getItem("user");
return currentUser;
}
function signOut() {
sessionStorage.removeItem("user");
localStorage.removeItem("user");
localStorage.removeItem("keepLoggedIn");
window.location = "index.html";
}
// Window
window.onload = function() {
getUsername();
if (currentUser === null) {
userlink.innerText = "Create Account";
userlink.classList.replace("rd-nav-link", "btn");
userlink.classList.add("btn-primary");
userlink.href = "../LoginOverView/index.html";
signoutlink.hidden = true;
signoutlink.innerText = "Login";
signoutlink.classList.replace("rd-nav-link", "btn");
signoutlink.classList.add("btn-success");
signoutlink.href = "./pages/LoginOverView/index.html";
} else {
userlink.innerText = currentUser;
header.innerText = "Sign In successfully";
userlink.classList.replace("btn", "rd-nav-link");
userlink.classList.add("btn-primary");
userlink.href = "../loginOverview/index.html";
signoutlink.hidden = false;
signoutlink.innerText = "Sign Out";
signoutlink.classList.replace("btn", "rd-nav-link");
signoutlink.classList.add("btn-success");
// Check if signoutlink exists before adding event listener
if (signoutlink) {
signoutlink.addEventListener("click", signOut);
}
}
};