Skip to content

Instantly share code, notes, and snippets.

@chiehwen
Created March 7, 2017 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiehwen/07a1956326604def6f7938e822c4a171 to your computer and use it in GitHub Desktop.
Save chiehwen/07a1956326604def6f7938e822c4a171 to your computer and use it in GitHub Desktop.
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