mirror of
https://github.com/hansjone/netx.git
synced 2026-10-12 14:10:49 +08:00
fix(topology): send auth token on discover stream requests
The SSE discover endpoint used raw fetch without Authorization, so login sessions got unauthorized after auth was enabled. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
a3bdad5be1
commit
325bce0413
1 changed files with 8 additions and 3 deletions
|
|
@ -563,15 +563,20 @@ export async function discoverTopologyNeighborsStream(
|
||||||
handlers: TopologyDiscoverStreamHandlers,
|
handlers: TopologyDiscoverStreamHandlers,
|
||||||
signal?: AbortSignal,
|
signal?: AbortSignal,
|
||||||
): Promise<TopologyDiscoverOut> {
|
): Promise<TopologyDiscoverOut> {
|
||||||
const res = await fetch(`/v1/topology/maps/${encodeURIComponent(mapId)}/discover/stream`, {
|
const path = `/v1/topology/maps/${encodeURIComponent(mapId)}/discover/stream`;
|
||||||
|
const res = await fetch(path, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: authHeaders({
|
||||||
accept: "text/event-stream",
|
accept: "text/event-stream",
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
},
|
}),
|
||||||
body: JSON.stringify(body || {}),
|
body: JSON.stringify(body || {}),
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
if (res.status === 401) {
|
||||||
|
handleUnauthorized(path);
|
||||||
|
throw new Error("unauthorized");
|
||||||
|
}
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const text = await res.text().catch(() => "");
|
const text = await res.text().catch(() => "");
|
||||||
throw new Error(text || `discover_stream_failed:${res.status}`);
|
throw new Error(text || `discover_stream_failed:${res.status}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue