remove mongo hash middleware

This commit is contained in:
Alex Holliday committed 2026-02-07 21:15:58 +00:00
1 parent 7e527b8eb2
commit 2e3b32462f
2 files changed
+17 -23

No files matched your search

-18
View File
@@ -50,24 +50,6 @@ const UserSchema = new Schema<UserDocument>(
{ timestamps: true }
);
UserSchema.pre("save", function (next) {
if (!this.isModified("password")) {
return next();
}
const salt = bcrypt.genSaltSync(10);
this.password = bcrypt.hashSync(this.password, salt);
next();
});
UserSchema.pre("findOneAndUpdate", function (next) {
const update = this.getUpdate();
if (update && "password" in update) {
const salt = bcrypt.genSaltSync(10);
(update as any).password = bcrypt.hashSync((update as any).password, salt);
}
next();
});
UserSchema.pre("findOneAndDelete", async function (next) {
try {
const userToDelete = await this.model.findOne(this.getFilter());