the domain-401 fix: a probe's auth refusal no longer ends the session -- the client's global 401 interceptor learns the opt-out. The production bug (the box deployment's first claim, 2026-11-29): the add route deliberately answers 401/403 when the discovery probe meets an auth refusal (the ruled design -- the failure carries its status for the SPA's password branch), but the client's one fetch choke point treated every 401 as a rejected token: clearToken, state.me null, render to the claim view. The op was kicked mid-add and locked out (the token is returned once, the server stores hashes only -- recovery was the db drop and re-bootstrap, the op's ruling). The fix: ApiOpts gains domain401, the interceptor skips the session teardown when the call site sets it, and all four provider call sites do -- the o/f add (its 401 is upstream breakage, still not session death), the custom add, the form's send-key, the card's send-key. Verified: typecheck green both programs, and a browser pass on --mock --debug driving the whole machine -- mock-auth added, the 401 lands, the banner and the key field open, the token survives, the claim view stays hidden, the key lands through the auth route, the card reads mock-auth 3 scraped unrefined; the only console line is the expected 401 resource entry. The smoke does not cover the client and the server behavior is unchanged; the pass is the verification.
This commit is contained in:
+7
-3
@@ -5,8 +5,8 @@
|
||||
// every path leads there until a fresh one is claimed.
|
||||
|
||||
/** @typedef {import('../server/shapes.mjs').HttpError} HttpError */
|
||||
/** One api() call: method + body + the keepalive flag. */
|
||||
/** @typedef {{ method?: string, body?: unknown, keepalive?: boolean }} ApiOpts */
|
||||
/** One api() call: method + body + the keepalive flag + the domain-401 flag. */
|
||||
/** @typedef {{ method?: string, body?: unknown, keepalive?: boolean, domain401?: boolean }} ApiOpts */
|
||||
|
||||
import { logEvent } from './log.mjs';
|
||||
import { state } from './state.mjs';
|
||||
@@ -40,7 +40,11 @@ export async function api(path, opts = {}) {
|
||||
e.detail = data.detail;
|
||||
e.status = res.status;
|
||||
logEvent('api', `${label} ${res.status} ${Math.round(performance.now() - started)}ms -- ${e.message}`);
|
||||
if (res.status === 401 && path !== '/session' && authToken()) {
|
||||
// a 401 ends the session -- except the provider probe routes,
|
||||
// where 401/403 is the endpoint's own auth refusal answering the
|
||||
// add or the key check (the SPA's password branch, by design);
|
||||
// those call sites opt out with domain401
|
||||
if (res.status === 401 && path !== '/session' && authToken() && !opts.domain401) {
|
||||
clearToken();
|
||||
state.me = null;
|
||||
logEvent('nav', 'signed out: token rejected');
|
||||
|
||||
Reference in New Issue
Block a user