Skip to content

Instantly share code, notes, and snippets.

@wheresvic
Last active October 24, 2016 20:08
Show Gist options
  • Save wheresvic/525b049e88995669f168ea190948c83a to your computer and use it in GitHub Desktop.
Save wheresvic/525b049e88995669f168ea190948c83a to your computer and use it in GitHub Desktop.
var authenticateUser = function(req, res, next) {
User.findOne({ username: req.body.username }, function(errFindUser, user) {
if (errFindUser) return next(errFindUser);
if (user) {
return user.verifyPassword(req.body.password, function(errVerifyPassword, isPasswordMatch) {
if (errVerifyPassword) return next(errVerifyPassword);
if (isPasswordMatch) {
return issueToken(user._id, function(errIssueToken, token) {
if (errIssueToken) return next(errIssueToken);
res.status(200).send(token);
});
}
res.status(401).send();
});
}
res.status(401).send();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment