-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
28 lines (26 loc) · 863 Bytes
/
init.js
File metadata and controls
28 lines (26 loc) · 863 Bytes
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
class Auth {
// setup the class and hide the body by default
constructor() {
document.querySelector("body").style.display = "none";
const auth = localStorage.getItem("auth");
this.validateAuth(auth);
}
// check to see if the localStorage item passed to the function is valid and set
validateAuth(auth) {
if (auth != 1) {
window.location.replace("/auth");
} else {
document.querySelector("body").style.display = "block";
}
}
// will remove the localStorage item and redirect to login screen
logOut() {
localStorage.setItem("auth", 0);
localStorage.setItem("authToken", 0);
window.location.replace("/auth");
}
}
const auth = new Auth();
document.querySelector(".logout").addEventListener("click", (e) => {
auth.logOut();
});