Skip to content

Instantly share code, notes, and snippets.

@sungwoncho
Created October 3, 2016 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sungwoncho/3debebf11704a60d09108aa739b09baf to your computer and use it in GitHub Desktop.
Save sungwoncho/3debebf11704a60d09108aa739b09baf to your computer and use it in GitHub Desktop.
login(req, res) {
const { username, shaHash } = req.body;
res.setHeader('Content-Type', 'application/json');
User.findOne({ username, verified: true }, (err, user) => {
if (!user) {
console.log('No user with that username found or not verified');
res.status(500);
res.end();
return;
}
console.log('user', user);
bcrypt.compare(shaHash, user.password, (err, isMatch) => {
if (err) {
console.log('err', err);
res.status(500);
res.end();
return;
}
if (isMatch) {
res.status(200);
res.end(JSON.stringify(user));
} else {
res.status(500);
res.end();
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment