Fix: Add Authorization header from authProvider tokens in custom fetch for SSE
This commit is contained in:
parent
89177a5ac5
commit
9258e2f6c4
2 changed files with 3508 additions and 9 deletions
3495
package-lock.json
generated
Normal file
3495
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -85,16 +85,20 @@ export async function connectToRemoteServer(
|
||||||
|
|
||||||
// Create transport with eventSourceInit to pass Authorization header if present
|
// Create transport with eventSourceInit to pass Authorization header if present
|
||||||
const eventSourceInit = {
|
const eventSourceInit = {
|
||||||
fetch: (url: string | URL, init: RequestInit | undefined) => {
|
fetch: (url: string | URL, init?: RequestInit) => {
|
||||||
return fetch(url, {
|
return Promise.resolve(authProvider?.tokens?.()).then((tokens) =>
|
||||||
...init,
|
fetch(url, {
|
||||||
headers: {
|
...init,
|
||||||
...init?.headers,
|
headers: {
|
||||||
...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, {
|
const transport = new SSEClientTransport(url, {
|
||||||
authProvider,
|
authProvider,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue