aboutsummaryrefslogtreecommitdiff
path: root/interface/public/verify.js
blob: 2351badc62c06c2caee69b9a0c205fb53f179be4 (plain)
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();
}