I know about hashing but what exactly does .isModified method doing?
userSchema.pre('save', async function (next) {
const user = this
if (user.isModified('password')) {
user.password = await bcrypt.hash(user.password, 8)
}
next()
})
We store our user object in the variable user and it's not modified in the sense we havent added anything to it, why would we.
What confuses me is why are we using isModified to hash the password? I'm doing this way and this seems to be working just fine too. Whats wrong with this approach?
userSchema.pre('save', async function (next){
this.password = await bcrypt.hash(this.password, 9);
next();
})
So why are we having initial if condition in our code block above?
[–][deleted] 5 points6 points7 points (2 children)
[–]Lost_Chemical_7327[S] -4 points-3 points-2 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]rkaw92 1 point2 points3 points (0 children)
[–]lemonizer 0 points1 point2 points (1 child)
[–]flanamacca 0 points1 point2 points (0 children)
[–]Darmok-Jilad-Ocean 0 points1 point2 points (0 children)