Skip to content

Commit

Permalink
Merge pull request #30 from feathersjs/fix-async-hook
Browse files Browse the repository at this point in the history
hashPassword: Async bcrypt usage needs a promise
  • Loading branch information
marshallswain authored and daffl committed Aug 29, 2018
1 parent fff3572 commit b854980
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/authentication/src/hooks/hash-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import bcrypt from 'bcrypt';
*/
exports.hashPassword = function(passwordField = 'password'){
return function(hook) {
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(hook.data[passwordField], salt, function(err, hash) {
if (err) {
throw new Error(err);
} else {
hook.data[passwordField] = hash;
}
return new Promise(function(resolve, reject){
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(hook.data[passwordField], salt, function(err, hash) {
if (err) {
reject(err);
} else {
hook.data[passwordField] = hash;
resolve(hook);
}
});
});
});
};
Expand Down

0 comments on commit b854980

Please sign in to comment.