-
Notifications
You must be signed in to change notification settings - Fork 0
fix: initialize CSRF cookies by calling Studio base URL #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||
APP_INIT_ERROR, APP_READY, subscribe, initialize, mergeConfig, getConfig, getPath, | ||||||||||||||||||||||||||||
APP_INIT_ERROR, APP_READY, subscribe, initialize, mergeConfig, getConfig, getPath, APP_AUTH_INITIALIZED, | ||||||||||||||||||||||||||||
} from '@edx/frontend-platform'; | ||||||||||||||||||||||||||||
import { AppProvider, ErrorPage } from '@edx/frontend-platform/react'; | ||||||||||||||||||||||||||||
import React, { StrictMode, useEffect } from 'react'; | ||||||||||||||||||||||||||||
|
@@ -14,6 +14,7 @@ import { | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import { initializeHotjar } from '@edx/frontend-enterprise-hotjar'; | ||||||||||||||||||||||||||||
import { logError } from '@edx/frontend-platform/logging'; | ||||||||||||||||||||||||||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||||||||||||||||||||||||||||
import messages from './i18n'; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||
|
@@ -151,6 +152,30 @@ subscribe(APP_INIT_ERROR, (error) => { | |||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
subscribe(APP_AUTH_INITIALIZED, () => { | ||||||||||||||||||||||||||||
getAuthenticatedHttpClient().interceptors.request.use(async (requestConfig) => { | ||||||||||||||||||||||||||||
const methodsToIntercept = ['post', 'put', 'delete', 'patch']; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if (methodsToIntercept.includes(requestConfig.method?.toLowerCase())) { | ||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||
await getAuthenticatedHttpClient().get(getConfig().STUDIO_BASE_URL, { | ||||||||||||||||||||||||||||
Comment on lines
+156
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Repeated calls to getAuthenticatedHttpClient() inside the interceptor can be replaced by a captured constant (e.g., const client = getAuthenticatedHttpClient();) to make intent clearer and avoid any risk if the factory were to return a new instance in future changes.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
pganesh-apphelix marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
withCredentials: true, | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||||||||||
pganesh-apphelix marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
const iframe = document.createElement('iframe'); | ||||||||||||||||||||||||||||
iframe.style.display = 'none'; | ||||||||||||||||||||||||||||
iframe.src = getConfig().STUDIO_BASE_URL; | ||||||||||||||||||||||||||||
document.body.appendChild(iframe); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
iframe.onload = () => { | ||||||||||||||||||||||||||||
setTimeout(() => document.body.removeChild(iframe), 2000); | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
pganesh-apphelix marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return requestConfig; | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
initialize({ | ||||||||||||||||||||||||||||
handlers: { | ||||||||||||||||||||||||||||
config: () => { | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registering the interceptor inside the event callback without a guard can lead to multiple identical interceptors if APP_AUTH_INITIALIZED fires more than once, causing duplicated priming requests. Add a flag to ensure the interceptor is added only once or store/eject the interceptor ID if re-registration is attempted.
Copilot uses AI. Check for mistakes.