changing the login link based on auth
This commit is contained in:
parent
769a24dff3
commit
a9ab175407
@ -32,9 +32,6 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="/">Home</a>
|
<a class="nav-link active" aria-current="page" href="/">Home</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/virtual-terminal">Virtual Terminal</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
<a class="nav-link dropdown-toggle"
|
<a class="nav-link dropdown-toggle"
|
||||||
href="#"
|
href="#"
|
||||||
@ -50,13 +47,14 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item dropdown">
|
<li id="vt-link" class="nav-item d-none">
|
||||||
|
<a class="nav-link" href="/virtual-terminal">Virtual Terminal</a>
|
||||||
|
</li>
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
<li class="nav-item">
|
<li id="login-link" class="nav-item d-none">
|
||||||
<a href="/login" class="nav-link">Login</a>
|
<a href="/login" class="nav-link">Login</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -69,6 +67,7 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
||||||
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="/static/js/base.js"></script>
|
||||||
{{ block "js" . }}
|
{{ block "js" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</body>
|
</body>
|
||||||
|
19
static/js/base.js
Normal file
19
static/js/base.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
let loginLink = document.getElementById("login-link");
|
||||||
|
let vtLink = document.getElementById("vt-link");
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
if (localStorage.getItem("token") !== null) {
|
||||||
|
loginLink.innerHTML = '<a href="#!" onclick="logout()" class="nav-link">Logout</a>';
|
||||||
|
vtLink.classList.remove('d-none');
|
||||||
|
} else {
|
||||||
|
loginLink.innerHTML = '<a href="/login" class="nav-link">Login</a>';
|
||||||
|
}
|
||||||
|
loginLink.classList.remove('d-none')
|
||||||
|
});
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
localStorage.removeItem("token");
|
||||||
|
localStorage.removeItem("token_expiry");
|
||||||
|
location.href = "/login";
|
||||||
|
}
|
||||||
|
|
@ -36,6 +36,7 @@ export function val(api) {
|
|||||||
localStorage.setItem("token", response.authentication_token.token);
|
localStorage.setItem("token", response.authentication_token.token);
|
||||||
localStorage.setItem("token_expiry", response.authentication_token.expiry);
|
localStorage.setItem("token_expiry", response.authentication_token.expiry);
|
||||||
showSuccess("login-messages", "Login successful.")
|
showSuccess("login-messages", "Login successful.")
|
||||||
|
location.href = "/";
|
||||||
} else {
|
} else {
|
||||||
showError("login-messages", response.message)
|
showError("login-messages", response.message)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user