Created
March 7, 2017 02:33
-
-
Save chiehwen/07a1956326604def6f7938e822c4a171 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