Skip to content

Commit

Permalink
Add xsrf token in the event source too
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jun 28, 2024
1 parent b0af4a9 commit 0ab828d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ export function eventStream(
onError: (error: Event) => void
): EventSource {
const settings = ServerConnection.makeSettings();
const requestUrl = URLExt.join(
let requestUrl = URLExt.join(
settings.baseUrl,
'jupyterlab-gallery', // API Namespace
endPoint
);
const xsrfTokenMatch = document.cookie.match('\\b_xsrf=([^;]*)\\b');
if (xsrfTokenMatch) {
const fullUrl = new URL(requestUrl);
fullUrl.searchParams.append('_xsrf', xsrfTokenMatch[1]);
requestUrl = fullUrl.toString();
}
const eventSource = new EventSource(requestUrl);
eventSource.addEventListener('message', event => {
const data = JSON.parse(event.data);
Expand Down

0 comments on commit 0ab828d

Please sign in to comment.