Skip to content

Commit

Permalink
fix: add back passwordValidatorPromisified
Browse files Browse the repository at this point in the history
  • Loading branch information
saintedlama committed Feb 27, 2018
1 parent bf6c837 commit 4794266
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ module.exports = function(schema, options) {
options.digestAlgorithm = options.digestAlgorithm || 'sha256'; // To get a list of supported hashes use crypto.getHashes()
options.passwordValidator = options.passwordValidator || function(password, cb) { cb(null); };

options.passwordValidatorPromisified = (password) => {
return new Promise((resolve, reject) => {
const maybePromise = options.passwordValidator(password, (err) => err?reject(err):resolve());

if (maybePromise && maybePromise.then && maybePromise.catch) {
maybePromise.then(() => resolve);
maybePromise.catch((err) => reject(err));
}
});
};

// Populate field names with defaults if not set
options.usernameField = options.usernameField || 'username';
options.usernameUnique = options.usernameUnique === undefined ? true : options.usernameUnique;
Expand Down

0 comments on commit 4794266

Please sign in to comment.