Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Last active January 9, 2022 19:08
Show Gist options
  • Save PatrickKalkman/dbc97521b56f4fe36356e1dc040b6a8b to your computer and use it in GitHub Desktop.
Save PatrickKalkman/dbc97521b56f4fe36356e1dc040b6a8b to your computer and use it in GitHub Desktop.
Enabling two factor authentication step 1
userController.enableTwoFactorAuthStep1 = function (req, reply) {
tokenVerification.extractAndVerifyToken(req, (err, isValidToken, email) => {
if (!err && isValidToken) {
const secret = speakeasy.generateSecret();
qrcode.toDataURL(secret.otpauth_url, function (err, qrImage) {
if (!err) {
reply.code(200).send({ qr: qrImage, secret: secret });
} else {
reply.internalServerError(err);
}
});
} else {
reply.unauthorized(err);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment