@@ -892,6 +892,10 @@ let currentRole = null;
|
||||
async function checkSession() {
|
||||
try {
|
||||
const res = await fetch('/api/session');
|
||||
if (res.redirected || !res.ok) {
|
||||
window.location.replace('/login.php');
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
if (data.loggedin) {
|
||||
currentUser = data.username;
|
||||
@@ -901,10 +905,27 @@ async function checkSession() {
|
||||
document.getElementById('settingsBtn').classList.remove('d-none');
|
||||
}
|
||||
} else {
|
||||
window.location.href = '/login.php';
|
||||
window.location.replace('/login.php');
|
||||
}
|
||||
} catch (e) {
|
||||
window.location.href = '/login.php';
|
||||
// Retry once after a brief delay in case of transient network issue
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/session');
|
||||
if (!res.ok || res.redirected) throw new Error();
|
||||
const data = await res.json();
|
||||
if (data.loggedin) {
|
||||
currentUser = data.username;
|
||||
currentRole = data.role;
|
||||
document.getElementById('userDisplay').textContent = data.username;
|
||||
if (data.role === 'admin' || data.admin_count === 0) {
|
||||
document.getElementById('settingsBtn').classList.remove('d-none');
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (_) {}
|
||||
window.location.replace('/login.php');
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user