Skip to content

Instantly share code, notes, and snippets.

@wheresvic
Created October 24, 2016 20:09
Show Gist options
  • Save wheresvic/0272c92a5ffec2874d6c184b982aafdb to your computer and use it in GitHub Desktop.
Save wheresvic/0272c92a5ffec2874d6c184b982aafdb to your computer and use it in GitHub Desktop.
const authenticateUser = function(req, res, next) {
Promise.coroutine(function*() {
try {
let user = yield User.findOne({ username: req.body.username });
if (user) {
let isPasswordMatch = yield user.verifyPassword(req.body.password);
if (isPasswordMatch) {
let token = yield issueToken(user._id);
res.status(200).send(token);
return;
}
}
res.status(401).send();
} catch (err) {
next(err);
}
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment