Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created January 15, 2022 13:50
Show Gist options
  • Save PatrickKalkman/462c9fe4a25f5b6fd61f268613eb95cc to your computer and use it in GitHub Desktop.
Save PatrickKalkman/462c9fe4a25f5b6fd61f268613eb95cc to your computer and use it in GitHub Desktop.
Validate token when logging in
userController.validateToken = function (req, reply) {
tokenVerification.extractAndVerifyJwtToken(req, (err, isValidJwtToken, email) => {
if (!err && isValidJwtToken) {
const user = db.getUser(email);
if (typeof user !== 'undefined') {
const validated = speakeasy.totp.verify({
secret: user.secret,
encoding: 'base32',
token: req.body.token,
});
reply.code(200).send({ validated });
}
} else {
reply.unauthorized(err);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment