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:
parent
4eb27543e5
commit
4d5a65a185
2 changed files with 187 additions and 9 deletions
|
|
@ -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]);
|
||||
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue