From fcd57cac00f28e8d3db09f0b0d0511bfea671ed7 Mon Sep 17 00:00:00 2001 From: anshul23102 Date: Thu, 4 Jun 2026 02:58:48 +0530 Subject: [PATCH] Add missing next() call in Mongoose pre-save middleware hook (Issue #699) Ensure proper middleware chain execution by calling next() in the pre-save hook. This prevents middleware chain interruption and ensures subsequent hooks are invoked correctly. Changes: - Added next parameter to pre-save hook - Call next() when password modification check returns early - Call next() at end of middleware to allow next hook execution - Maintains compatibility with Mongoose middleware chain Fixes #699 --- backend/models/User.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/models/User.js b/backend/models/User.js index eb506ed5..3aeaf9b2 100644 --- a/backend/models/User.js +++ b/backend/models/User.js @@ -18,12 +18,12 @@ const UserSchema = new mongoose.Schema({ }, }); -// ✅ FIXED: no next() -UserSchema.pre('save', async function () { - if (!this.isModified('password')) return; +UserSchema.pre('save', async function (next) { + if (!this.isModified('password')) return next(); const salt = await bcrypt.genSalt(10); this.password = await bcrypt.hash(this.password, salt); + next(); }); // ✅ password comparison