auth: park login flow — circle back
Auth work is parked until after ship. While AUTH_ENABLED=false:
- login.html now auto-redirects to / on load (no one should ever see
the login screen while auth is off; it was confusing).
- sidebar power button is hidden entirely when /auth/me returns a
synthetic user, so there's no broken-feeling no-op control.
- Removed connect-pg-simple createTableIfMissing flag in case
v9.0.1's handling of that option was responsible for the recent
boot 502 (the schema is created by migration 021 anyway).
The /auth/login + session.regenerate() + cookie fix from c34a721
stays in place — when we re-enable auth it'll work end-to-end. The
sessions table from migration 021 stays. Operator action to restore
auth later: set AUTH_ENABLED=true + SESSION_SECRET=<random> in the
mam-api environment and restart.
This commit is contained in:
parent
34bf1c7b7f
commit
d1f9557dd1
3 changed files with 17 additions and 24 deletions
|
|
@ -78,9 +78,6 @@ app.use(
|
||||||
pool,
|
pool,
|
||||||
tableName: 'sessions',
|
tableName: 'sessions',
|
||||||
pruneSessionInterval: 3600,
|
pruneSessionInterval: 3600,
|
||||||
// Belt-and-braces: connect-pg-simple will CREATE TABLE on its first
|
|
||||||
// write if migration 021 somehow didn't run. Cheap, idempotent.
|
|
||||||
createTableIfMissing: true,
|
|
||||||
}),
|
}),
|
||||||
secret: SESSION_SECRET,
|
secret: SESSION_SECRET,
|
||||||
resave: false,
|
resave: false,
|
||||||
|
|
|
||||||
|
|
@ -264,23 +264,22 @@
|
||||||
$('show-setup').onclick = e => { e.preventDefault(); clearFlash(); showSetup(); };
|
$('show-setup').onclick = e => { e.preventDefault(); clearFlash(); showSetup(); };
|
||||||
$('show-login').onclick = e => { e.preventDefault(); clearFlash(); showLogin(); };
|
$('show-login').onclick = e => { e.preventDefault(); clearFlash(); showLogin(); };
|
||||||
|
|
||||||
// First-run detection: if no users exist, skip the sign-in panel entirely
|
// Auth is parked for now. If the server reports auth is disabled, bounce
|
||||||
// and present the create-admin form. This is the only state in which the
|
// straight to the app — no one should ever land on this screen while
|
||||||
// app is unusable without intervention, so we want the operator routed
|
// AUTH_ENABLED=false. If the server is unreachable, leave the panel
|
||||||
// there automatically rather than relying on them to click the small link.
|
// visible so the operator at least sees something.
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const r = await fetch(API + '/setup-status', { credentials: 'same-origin' });
|
const r = await fetch(API + '/setup-status', { credentials: 'same-origin' });
|
||||||
if (r.ok) {
|
if (r.ok) {
|
||||||
const d = await r.json();
|
const d = await r.json();
|
||||||
|
if (!d.auth_enabled) {
|
||||||
|
location.replace('/');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (d.needs_setup) {
|
if (d.needs_setup) {
|
||||||
showSetup();
|
showSetup();
|
||||||
showFlash('No accounts yet — create the first admin to continue.', 'info');
|
showFlash('No accounts yet — create the first admin to continue.', 'info');
|
||||||
} else if (!d.auth_enabled) {
|
|
||||||
// Auth is off server-side; logging in does nothing. Tell the
|
|
||||||
// operator clearly instead of letting them fill out the form
|
|
||||||
// and watch the redirect loop back to /login.html.
|
|
||||||
showFlash('Authentication is disabled on the server (AUTH_ENABLED=false). Set AUTH_ENABLED=true in mam-api and restart.', 'error');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (_) { /* offline → leave the login panel visible */ }
|
} catch (_) { /* offline → leave the login panel visible */ }
|
||||||
|
|
|
||||||
|
|
@ -177,18 +177,15 @@ function Sidebar({ active, onNavigate, me, collapsed, onToggle }) {
|
||||||
{me?.role || '—'}{me?.synthetic ? ' · auth off' : ''}
|
{me?.role || '—'}{me?.synthetic ? ' · auth off' : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button className="icon-btn" aria-label="Sign out" data-tip="Sign out" title="Sign out"
|
{me?.synthetic ? null : (
|
||||||
onClick={async () => {
|
<button className="icon-btn" aria-label="Sign out" data-tip="Sign out" title="Sign out"
|
||||||
// Best-effort logout — works whether auth is on or off. With
|
onClick={async () => {
|
||||||
// AUTH_ENABLED=true the server clears the session; with auth
|
try { await window.ZAMPP_API.fetch('/auth/logout', { method: 'POST' }); } catch (_) {}
|
||||||
// off there's no session, so we still bounce to /login.html
|
window.location.replace('/login.html');
|
||||||
// so the operator can see "auth disabled" messaging and choose
|
}}>
|
||||||
// to enable it instead of staring at a no-op power button.
|
<Icon name="power" />
|
||||||
try { await window.ZAMPP_API.fetch('/auth/logout', { method: 'POST' }); } catch (_) {}
|
</button>
|
||||||
window.location.replace('/login.html');
|
)}
|
||||||
}}>
|
|
||||||
<Icon name="power" />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue