Last active
August 29, 2015 14:26
-
-
Save Ntropish/a1a0a0b1cf3a8a1ad81d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
passport.use(new LocalStrategy(function (username, password, done) { | |
'use strict'; | |
var findUser = User.findOne({username: username}).exec(); | |
var verifyUserPassword = findUser.then(function(user){ | |
return new Promise(function(resolve, reject) { | |
if (!user) { | |
// Password can't match against a nonexistent user's password | |
return resolve({isMatch:false, user:user}); | |
} | |
user.verifyPassword(password, function (err, isMatch) { | |
if (err) { | |
return reject(err); | |
} | |
resolve({isMatch:isMatch, user:user}); | |
}); | |
}); | |
}, function(err) { | |
return done(err); | |
}); | |
verifyUserPassword.then(function(results){ | |
return done(null, results.isMatch ? results.user : false) | |
}, function(err){ | |
return done(err); | |
}); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment