Skip to content

Comments

fix(auth): prevent double response in OAuth profile validation flow#3140

Merged
PierreBrisorgueil merged 3 commits intomasterfrom
codex/fix-issue-3136
Feb 21, 2026
Merged

fix(auth): prevent double response in OAuth profile validation flow#3140
PierreBrisorgueil merged 3 commits intomasterfrom
codex/fix-issue-3136

Conversation

@PierreBrisorgueil
Copy link
Contributor

Summary

  • stop checkOAuthUserProfile from writing directly to res on validation failure
  • throw AppError (VALIDATION_ERROR) instead, so oauthCallback remains the single response boundary
  • keep a clean client error contract in oauthCallback using responses.error(...) + errors.getMessage(...)
  • update OAuth integration tests to assert thrown validation errors rather than direct response writes

Why

The previous flow could return an Express response object from checkOAuthUserProfile, then continue in oauthCallback as if it were a user object, which may trigger incorrect auth flow and ERR_HTTP_HEADERS_SENT.

Validation

  • npx eslint modules/auth/controllers/auth.controller.js modules/auth/tests/auth.integration.tests.js
  • Integration test run is blocked in this environment by local MongoDB access (EPERM 127.0.0.1:27017)

Closes #3136

- 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
Copilot AI review requested due to automatic review settings February 21, 2026 14:46
@PierreBrisorgueil PierreBrisorgueil added Fix A bug fix Severity3: broken Bug qualification labels Feb 21, 2026
@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.61%. Comparing base (cf3a66d) to head (08a1689).
⚠️ Report is 3 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 checkOAuthUserProfile to throw errors instead of writing responses
  • Updated error handling in oauthCallback to 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

@PierreBrisorgueil PierreBrisorgueil merged commit 8c99c22 into master Feb 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix A bug fix Severity3: broken Bug qualification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(auth): fix checkOAuthUserProfile error propagation (avoid writing to res)

1 participant