-
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
Conversation
91e1f89
to
3ecc363
Compare
3ecc363
to
5fc6f9b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7 +/- ##
=======================================
Coverage 94.69% 94.69%
=======================================
Files 1204 1204
Lines 26854 26854
Branches 6025 6026 +1
=======================================
Hits 25430 25430
- Misses 1354 1365 +11
+ Partials 70 59 -11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3baa958
to
1bc41b6
Compare
1bc41b6
to
d3cf40f
Compare
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.
LGTM!
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.
Pull Request Overview
Purpose: Initialize CSRF cookies by touching the Studio base URL before mutating (POST/PUT/PATCH/DELETE) requests.
- Adds APP_AUTH_INITIALIZED subscription that installs an axios request interceptor.
- Interceptor prefaces mutating requests with a GET to STUDIO_BASE_URL, falling back to a hidden iframe if the GET fails.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
||
subscribe(APP_AUTH_INITIALIZED, () => { |
Copilot
AI
Oct 17, 2025
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.
subscribe(APP_AUTH_INITIALIZED, () => { | |
// Guard to ensure the interceptor is only registered once | |
let interceptorRegistered = false; | |
subscribe(APP_AUTH_INITIALIZED, () => { | |
if (interceptorRegistered) { | |
return; | |
} | |
interceptorRegistered = true; |
Copilot uses AI. Check for mistakes.
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, { |
Copilot
AI
Oct 17, 2025
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.
[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.
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, { | |
const client = getAuthenticatedHttpClient(); | |
client.interceptors.request.use(async (requestConfig) => { | |
const methodsToIntercept = ['post', 'put', 'delete', 'patch']; | |
if (methodsToIntercept.includes(requestConfig.method?.toLowerCase())) { | |
try { | |
await client.get(getConfig().STUDIO_BASE_URL, { |
Copilot uses AI. Check for mistakes.
No description provided.