Skip to content

Commit fcd57ca

Browse files
committed
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
1 parent 53f820b commit fcd57ca

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

backend/models/User.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ const UserSchema = new mongoose.Schema({
1818
},
1919
});
2020

21-
// ✅ FIXED: no next()
22-
UserSchema.pre('save', async function () {
23-
if (!this.isModified('password')) return;
21+
UserSchema.pre('save', async function (next) {
22+
if (!this.isModified('password')) return next();
2423

2524
const salt = await bcrypt.genSalt(10);
2625
this.password = await bcrypt.hash(this.password, salt);
26+
next();
2727
});
2828

2929
// ✅ password comparison

0 commit comments

Comments
 (0)