Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ UserSchema.pre('save', async function (next) {
this.password = await bcrypt.hash(this.password, salt);
});

// Encrypt password using bcrypt while updating (admin)
UserSchema.pre("findOneAndUpdate", async function (next) {
if (this._update.password) {
this._update.password = await bcrypt.hash(this._update.password, 10);
}
next();
});

// Sign JWT and return
UserSchema.methods.getSignedJwtToken = function () {
return jwt.sign({ id: this._id }, process.env.JWT_SECRET, {
Expand Down