Skip to content

Instantly share code, notes, and snippets.

@rla
Created December 7, 2016 12:12
Show Gist options
  • Save rla/f51798e5d99328d0c3ca1077b9fbe45d to your computer and use it in GitHub Desktop.
Save rla/f51798e5d99328d0c3ca1077b9fbe45d 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