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

Schema method returns 'undefined' #3678

Closed
OKNoah opened this issue Dec 16, 2015 · 2 comments
Closed

Schema method returns 'undefined' #3678

OKNoah opened this issue Dec 16, 2015 · 2 comments

Comments

@OKNoah
Copy link

OKNoah commented Dec 16, 2015

Here is the method:

User.methods.verifyPassword = function verifyPassword ( password ) {
  return bcrypt.compare( password, this.password )
}

Here it is used in the controller.

export function* login () {
  let self = this

  const user = yield User.findOne({ email: this.request.body.email }).exec()

  if ( user.verifyPassword(this.request.body.password) ) {
    this.status = 200
    this.body = {
      token: user.token
    }
  } else {
    this.status = 500
    this.body = "Problem signing in."
  }
}
@jiripospisil
Copy link

I'm not sure what bcrypt library you're using but doesn't the compare method take a callback as the third parameter (although I'm surprised it doesn't scream at you for not providing it)? There might be a synchronous version (compareSync) but ideally you should thunkify the async variant and yield in the controller.

@vkarpov15
Copy link
Collaborator

@jiripospisil is right, bcrypt.compare() is async.

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

No branches or pull requests

3 participants