Set Authorization header from client
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user