resolve database pipeline freeze by implementing next() callback in user pre-save hook#477
resolve database pipeline freeze by implementing next() callback in user pre-save hook#477Aryan0819 wants to merge 6 commits into
Conversation
❌ Deploy Preview for github-spy failed.
|
📝 WalkthroughWalkthroughFixes Mongoose pre-save password hashing middleware to use the explicit ChangesAuthentication updates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🎉 Thank you @Aryan0819 for your contribution. Please make sure your PR follows https://github.com/GitMetricsLab/github_tracker/blob/main/CONTRIBUTING.md#-pull-request-guidelines
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/models/User.js`:
- Around line 22-30: The pre-save hook UserSchema.pre('save', async function
(next) { ... }) should be converted to an async-only hook: remove the next
parameter and all next() calls; use early returns and thrown errors instead.
Specifically, change the hook signature to async function () { ... }, replace
"if (!this.isModified('password')) return next();" with "if
(!this.isModified('password')) return;", remove "next();" after hashing and in
the catch block rethrow the error (throw err) so Mongoose handles rejection.
This ensures the hook relies solely on promise/async completion semantics.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/config/passportConfig.js`:
- Line 10: Remove the duplicate semicolon at the end of the User lookup
statement; in the passport config callback where you call
User.findOne({email}).select("+password");; (reference the User model and the
select("+password") call), leave a single terminating semicolon so the statement
becomes syntactically correct.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a79ce458-59e2-4cbd-a02a-6ab511890502
📒 Files selected for processing (1)
backend/config/passportConfig.js
Refactor useDebounce hook for better readability
|
@mehul-m-prajapati please review this |
|
@Srijatalamarla @ASR1015 @md-asharaf please can you reveiw these pull request |
|
@mehul-m-prajapati can you please merge |
|
@mehul-m-prajapati @Srijatalamarla @ASR1015 @md-asharaf please merge this pr |
Updated pre-save hook to include next() for proper middleware flow and error handling.
Related Issue
Description
Description
🧱 The Architectural Context:
Mongoose middleware hooks (pre-save hooks) intercept data operations right before records are committed to MongoDB. In older versions of Mongoose, this relied heavily on explicitly calling a
next()callback. Modern Mongoose allows you to omitnext()only if the function returns a Promise that resolves naturally at the end of its block execution.How Has This Been Tested?
Profile Updates: Verified via Postman that modifying only the username or email returns an instant response without hanging or timing out.
Type of Change
Summary by CodeRabbit