Skip to content

Commit

Permalink
chore: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
saintedlama committed Jan 4, 2020
1 parent 857f93a commit 7992af4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ module.exports = function(schema, options) {
options.encoding = options.encoding || 'hex';
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.passwordValidatorAsync =
options.passwordValidatorAsync ||
function(password) {
return new Promise((resolve, reject) => {
options.passwordValidator(password, err => (err ? reject(err) : resolve()));
});
};
function defaultPasswordValidator(password, cb) {
cb(null);
}

function defaultPasswordValidatorAsync(password) {
return new Promise((resolve, reject) => {
options.passwordValidator(password, err => (err ? reject(err) : resolve()));
});
}

options.passwordValidator = options.passwordValidator || defaultPasswordValidator;
options.passwordValidatorAsync = options.passwordValidatorAsync || defaultPasswordValidatorAsync;

// Populate field names with defaults if not set
options.usernameField = options.usernameField || 'username';
Expand Down
2 changes: 1 addition & 1 deletion lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const generaterr = require('generaterr');
const AuthenticationError = generaterr('AuthenticationError');

module.exports = {
AuthenticationError: AuthenticationError,
AuthenticationError,
IncorrectUsernameError: generaterr('IncorrectUsernameError', null, { inherits: AuthenticationError }),
IncorrectPasswordError: generaterr('IncorrectPasswordError', null, { inherits: AuthenticationError }),
MissingUsernameError: generaterr('MissingUsernameError', null, { inherits: AuthenticationError }),
Expand Down

0 comments on commit 7992af4

Please sign in to comment.