Skip to content

Instantly share code, notes, and snippets.

@wheresvic
Created October 24, 2016 20:09
Show Gist options
  • Save wheresvic/ee30f0cfb1f1431465ff160a27c45ff5 to your computer and use it in GitHub Desktop.
Save wheresvic/ee30f0cfb1f1431465ff160a27c45ff5 to your computer and use it in GitHub Desktop.
const authenticateUser = async function(req, res, next) {
try {
let user = await User.findOne({ username: req.body.username });
if (user) {
let isPasswordMatch = await user.verifyPassword(req.body.password);
if (isPasswordMatch) {
let token = await 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