Fix admin login reload loop from stale localStorage tokens.
Clear client tokens on the login page, gate admin pages with shared cookie JWT checks, and clear Secure cookies reliably behind the proxy. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Authentication helpers: login, logout, page guard and header profile.
|
||||
* Session is stored in HttpOnly cookies by the server; localStorage is optional cache.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
/** Redirect to the login page when no access token is stored. */
|
||||
/**
|
||||
* Page shells are already gated by AdminPageAuth middleware.
|
||||
* Keep a soft client check for pages that still call this.
|
||||
*/
|
||||
function requireAuth() {
|
||||
if (!Api.tokens.access) {
|
||||
Api.redirectToLogin();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Sign in and store the token pair. */
|
||||
/** Sign in; server sets HttpOnly cookies. */
|
||||
async function login(loginValue, password) {
|
||||
const pair = await Api.post("/api/v1/admin/login", {
|
||||
login: loginValue,
|
||||
@@ -25,7 +25,12 @@
|
||||
Api.tokens.set(pair);
|
||||
}
|
||||
|
||||
function logout() {
|
||||
async function logout() {
|
||||
try {
|
||||
await Api.post("/api/v1/admin/logout", {});
|
||||
} catch (_) {
|
||||
/* still clear local state and leave */
|
||||
}
|
||||
Api.tokens.clear();
|
||||
window.location.href = "/admin/login";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user