Currently having issues trying to compare the password I hashed with bcrypt. It always returns false when I compare it. Look at the code below and let me know what am doing bad
userSchema.pre("save", async function (next) {
const salt = await bcrypt.genSalt();
this.password = await bcrypt.hash(this.password, salt);
next();
});
userSchema.statics.login = async function (email, password) {
const user = await this.findOne({ email });
if (user) {
const isMatch = await bcrypt.compare(password, user.password);
console.log(isMatch);
if (isMatch) {
return user;
}
throw Error("Incorrect password");
}
throw Error("Incorrect email");
};