Set Authorization header from client
This commit is contained in:
parent
874320ebe6
commit
af8877064e
1 changed files with 14 additions and 1 deletions
|
|
@ -146,7 +146,20 @@ export function useConnection({
|
||||||
backendUrl.searchParams.append("url", sseUrl);
|
backendUrl.searchParams.append("url", sseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientTransport = new SSEClientTransport(backendUrl);
|
const headers: HeadersInit = {};
|
||||||
|
const accessToken = sessionStorage.getItem(SESSION_KEYS.ACCESS_TOKEN);
|
||||||
|
if (accessToken) {
|
||||||
|
headers['Authorization'] = `Bearer ${accessToken}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientTransport = new SSEClientTransport(backendUrl, {
|
||||||
|
eventSourceInit: {
|
||||||
|
fetch: (url, init) => fetch(url, { ...init, headers }),
|
||||||
|
},
|
||||||
|
requestInit: {
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (onNotification) {
|
if (onNotification) {
|
||||||
client.setNotificationHandler(
|
client.setNotificationHandler(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue