Skip to content

Instantly share code, notes, and snippets.

@caulagi
Created February 28, 2021 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caulagi/1f6357bc52e2dee684e60465b23160e6 to your computer and use it in GitHub Desktop.
Save caulagi/1f6357bc52e2dee684e60465b23160e6 to your computer and use it in GitHub Desktop.
Find a user asynchronously from the database. If that succeeds, return the user. Else return the error
User.findOne({ email: email }, function (err, user) {
if (err) { return done(err) }
if (!user) {
return done(null, false, { message: ‘Unknown user’ })
}
if (!user.authenticate(password)) {
return done(null, false, { message: ‘Invalid password’ })
}
return done(null, user)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment