Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: a request that finds the login ended reloads the page to the login

The gateway answered every non-page request without a session with a login
redirect, which fetch and EventSource cannot follow across origins, so polls,
forms and streams failed with errors that said nothing about the session. It
now answers anything that does not ask for text/html with a 401 and a
WWW-Authenticate header, and the swarm UI reloads on that 401, from a wrapped
fetch (one place for every call) and from a probe after a stream dies. A second
reload within ten seconds is skipped so a page that keeps answering 401 cannot
loop. The proxy test and the docs follow.
This commit is contained in:
iris 2026-10-28 18:14:58 +01:00 • committed by mara
commit 4d5a65a185
2 changed files with 187 additions and 9 deletions

View file

@ -21,6 +21,7 @@ import {
connectionAfterError,
type ConnectionState,
} from "../../ui/stream/connection.js";
import { probeSession } from "../../ui/session/session.js";
export type { ConnectionState };
@ -87,7 +88,12 @@ export function useSwarmAgentStateStream(
// badge cluster over — the next valid header replaces it.
}
};
es.onerror = () => setConnection(connectionAfterError(es.readyState));
es.onerror = () => {
const state = connectionAfterError(es.readyState);
setConnection(state);
// The browser gave up: say whether the session ended, which `EventSource` does not tell.
if (state === "closed") probeSession();
};
return () => es.close();
}, [streamUrl, attempt]);

View file

@ -16,6 +16,7 @@ import {
connectionAfterError,
type ConnectionState,
} from "../../ui/stream/connection.js";
import { probeSession } from "../../ui/session/session.js";
export type { ConnectionState };
@ -68,7 +69,12 @@ export function useSwarmTermStream(
}
setRows((prev) => appendRow(prev, { ...msg, key, fromHistory: false }));
};
es.onerror = () => setConnection(connectionAfterError(es.readyState));
es.onerror = () => {
const state = connectionAfterError(es.readyState);
setConnection(state);
// The browser gave up: say whether the session ended, which `EventSource` does not tell.
if (state === "closed") probeSession();
};
return () => es.close();
}, [streamUrl, attempt]);