Skip to content

Commit b854980

Browse files
marshallswaindaffl
authored andcommitted
Merge pull request #30 from feathersjs/fix-async-hook
hashPassword: Async bcrypt usage needs a promise
1 parent fff3572 commit b854980

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎packages/authentication/src/hooks/hash-password.js‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import bcrypt from 'bcrypt';
77
*/
88
exports.hashPassword = function(passwordField = 'password'){
99
return function(hook) {
10-
bcrypt.genSalt(10, function(err, salt) {
11-
bcrypt.hash(hook.data[passwordField], salt, function(err, hash) {
12-
if (err) {
13-
throw new Error(err);
14-
} else {
15-
hook.data[passwordField] = hash;
16-
}
10+
return new Promise(function(resolve, reject){
11+
bcrypt.genSalt(10, function(err, salt) {
12+
bcrypt.hash(hook.data[passwordField], salt, function(err, hash) {
13+
if (err) {
14+
reject(err);
15+
} else {
16+
hook.data[passwordField] = hash;
17+
resolve(hook);
18+
}
19+
});
1720
});
1821
});
1922
};

0 commit comments

Comments
 (0)