fix(auth): prevent double response in OAuth profile validation flow#3140
fix(auth): prevent double response in OAuth profile validation flow#3140PierreBrisorgueil merged 3 commits intomasterfrom
Conversation
- Add `dev` alias for `start` (cross-stack consistency) - Add `test:unit` alias for `test` (one-shot, mirrors Vue naming) - Add `format` script (prettier already installed, script was missing) - Document `prod`, `format`, `test:unit`, `release` strategy in CLAUDE.md - Update README and copilot-instructions to reflect all scripts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3140 +/- ##
==========================================
+ Coverage 89.49% 89.61% +0.11%
==========================================
Files 52 52
Lines 1133 1136 +3
Branches 217 219 +2
==========================================
+ Hits 1014 1018 +4
Misses 107 107
+ Partials 12 11 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in the OAuth authentication flow where checkOAuthUserProfile was writing directly to the response object and then returning it to the caller, which could lead to double-response errors (ERR_HTTP_HEADERS_SENT). The fix refactors the function to throw AppError instances instead, allowing the calling oauthCallback function to remain the single response boundary.
Changes:
- Refactored
checkOAuthUserProfileto throw errors instead of writing responses - Updated error handling in
oauthCallbackto properly handle thrown validation errors - Updated integration tests to assert thrown errors instead of mocked response objects
- Added standard script aliases (
dev,test:unit,format) for consistency with stack conventions
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
modules/auth/controllers/auth.controller.js |
Removed res parameter from checkOAuthUserProfile; throws AppError for validation failures; enhanced error handling in oauthCallback catch block |
modules/auth/tests/auth.integration.tests.js |
Updated tests to verify thrown AppError instances instead of response writes; removed mock response objects from test calls |
package.json |
Added dev, test:unit, and format script aliases for consistency |
README.md |
Updated documentation to reflect new script aliases |
CLAUDE.md |
Updated command table with new aliases and descriptions |
.github/copilot-instructions.md |
Updated canonical commands list with new aliases |
Summary
checkOAuthUserProfilefrom writing directly toreson validation failureAppError(VALIDATION_ERROR) instead, sooauthCallbackremains the single response boundaryoauthCallbackusingresponses.error(...)+errors.getMessage(...)Why
The previous flow could return an Express response object from
checkOAuthUserProfile, then continue inoauthCallbackas if it were a user object, which may trigger incorrect auth flow andERR_HTTP_HEADERS_SENT.Validation
npx eslint modules/auth/controllers/auth.controller.js modules/auth/tests/auth.integration.tests.jsEPERM 127.0.0.1:27017)Closes #3136