..
Viewing
verify.js
24 lines (24 loc) • 666.0 B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 | const token = localStorage.getItem("token");
if (token) {
fetch("/api/verify", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
}
}).then(response => {
if (response.status === 200) {
$('#loginButton').hide();
$('#logoutButton').show();
} else {
localStorage.removeItem("token");
if (window.location.pathname !== "/") {
window.location.href = "/";
}
$('#loginButton').show();
$('#logoutButton').hide();
}
});
} else {
$('#loginButton').show();
$('#logoutButton').hide();
}
|
|