Created
October 24, 2016 20:09
-
-
Save wheresvic/ee30f0cfb1f1431465ff160a27c45ff5 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
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