fix: stray closing brace broke entire JS script + remove login gate for guest mode

This commit is contained in:
2026-05-28 22:16:43 -04:00
parent b07c30da5e
commit 3a8f89432a
7 changed files with 74 additions and 24 deletions
+14 -24
View File
@@ -1751,33 +1751,28 @@
// Try to restore session from localStorage or auto-login
async function initAuth() {
// Check for stored token
// Field tool mode — server accepts anonymous requests (falls back to admin).
// We skip auth entirely. If a stored session exists, use it for display
// but never gate the UI.
const stored = localStorage.getItem('canteen_session');
if (stored) {
try {
const session = JSON.parse(stored);
AppState.authToken = session.token;
// Validate token by fetching current user
const user = await api('/api/auth/me', {
AppState.currentUser = await api('/api/auth/me', {
headers: { 'Authorization': 'Bearer ' + session.token }
});
AppState.currentUser = user;
// Load settings now that we're authenticated
loadSettingsCache().then(() => {
populateCategorySelect('manCatSelect');
populateMakeSelect();
populateCustomerSelect();
loadBadgeChecklist();
});
}).catch(() => null);
} catch (e) {
// Token expired or invalid — clear it
localStorage.removeItem('canteen_session');
AppState.authToken = null;
AppState.currentUser = null;
}
}
if (!AppState.currentUser) {
// Guest mode — no token, server accepts anonymous
AppState.authToken = null;
AppState.currentUser = { username: 'Guest', role: 'guest' };
}
updateUserUI();
checkAuthGate();
hideLogin();
}
// =========================================================================
@@ -1821,9 +1816,6 @@
showToast('Welcome, ' + result.username + '!');
// Load settings now that we're authenticated
loadSettingsCache().then(() => {
populateCategorySelect('newCatSelect');
populateCategorySelect('ocrCatSelect');
populateCategorySelect('manCatSelect');
populateMakeSelect();
populateCustomerSelect();
loadBadgeChecklist();
@@ -1843,10 +1835,10 @@
} catch (e) { /* ignore — still clean up locally */ }
localStorage.removeItem('canteen_session');
AppState.authToken = null;
AppState.currentUser = null;
AppState.currentUser = { username: 'Guest', role: 'guest' };
updateUserUI();
showLogin();
showToast('Logged out');
hideLogin();
showToast('Logged out — running as guest');
}
function showLogin() {
@@ -3676,8 +3668,6 @@
document.getElementById('assetsEditView').style.display = 'block';
}
}
// ── Detail view ───────────────────────────────────────────────────────
function nvl(v, fallback) { return (v !== null && v !== undefined && v !== '') ? v : fallback; }