Fix: Add Authorization header from authProvider tokens in custom fetch for SSE

This commit is contained in:
dorshany 2025-04-13 14:12:12 -07:00
parent 89177a5ac5
commit 995316561e
2 changed files with 3508 additions and 9 deletions

3495
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -85,16 +85,20 @@ export async function connectToRemoteServer(
// Create transport with eventSourceInit to pass Authorization header if present
const eventSourceInit = {
fetch: (url: string | URL, init: RequestInit | undefined) => {
return fetch(url, {
...init,
headers: {
...init?.headers,
...headers,
},
})
fetch: (url: string | URL, init?: RequestInit) => {
return Promise.resolve(authProvider?.tokens?.()).then((tokens) =>
fetch(url, {
...init,
headers: {
...(init?.headers as Record<string, string> | undefined),
...headers,
...(tokens?.access_token ? { Authorization: `Bearer ${tokens.access_token}` } : {}),
Accept: "text/event-stream",
} as Record<string, string>,
})
);
},
}
};
const transport = new SSEClientTransport(url, {
authProvider,