Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange example code on http://everyauth.com/ #430

Open
MichaelJCole opened this issue Jun 18, 2013 · 0 comments
Open

Strange example code on http://everyauth.com/ #430

MichaelJCole opened this issue Jun 18, 2013 · 0 comments
Labels

Comments

@MichaelJCole
Copy link

Hi, I was looking through the example code on everyauth.com and found this snippet

// findUser passes an error or user to a callback after finding the
// user by login
findUser( login, function (err, user) {
  if (err) {
    errors.push(err.message || err);
    return promise.fulfill(errors);
  }
  if (!user) {
    errors.push('User with login ' + login + ' does not exist.');
    return promise.fulfill(errors);
  }
  bcrypt.compare(password, user.hash, function (err, didSucceed) {
    if (err) {
      return promise.fail(err);
      errors.push('Wrong password.');
      return promise.fulfill(errors);
    }
    if (didSucceed) return promise.fulfill(user);
    errors.push('Wrong password.');
    return promise.fulfill(errors);
  });
});
  1. The code after "return promise.fail(err);" won't be run. So that's confusing.
  2. I'm new to NodeJS, but I didn't see how the login var was in scope in this line:
    errors.push('User with login ' + login + ' does not exist.');

Anyways, this looks totally bad-ass and will save me a ton of time. Thanks for the work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants