Created
December 7, 2016 12:12
-
-
Save rla/f51798e5d99328d0c3ca1077b9fbe45d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.pre('save', wrap(async () => { | |
var user = this; | |
if (!user.isModified('password')) return; | |
var salt = await bcrypt.genSalt(10); | |
var hash = await bcrypts.hash(user.password, salt, null); | |
user.password = hash; | |
})); | |
const wrap = (fn) => { | |
return (next) => { | |
fn().then(() => { | |
next(); | |
}, next); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment