Answers for "bcryptjs compare 2021 problem"

0

bcryptjs compare 2021 problem

Somehow it used to work before feb 2021 but afterwards it just bugged...

For People like me who uses Bcryptjs for hashing / Crypting password 
that they pass to MongoDB:

If you have a:

 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();
 });

then add a this.isNew like: 
	
 userSchema.pre("save", async function (next) {
	if (!this.isModified("password") || this.isNew) return next();
    const salt = await bcrypt.genSalt(10);
	this.password = await bcrypt.hash(this.password, salt);
	next();
 });

Checkout the StackOverflow answer by Samso Maosa
Posted by: Guest on April-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language