Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2fa is not working on live server in nodejs #696

Open
farhanali2325 opened this issue Feb 15, 2023 · 1 comment
Open

2fa is not working on live server in nodejs #696

farhanali2325 opened this issue Feb 15, 2023 · 1 comment

Comments

@farhanali2325
Copy link

farhanali2325 commented Feb 15, 2023

Describe the bug
I've implemented optlib in node js and it's working fine on the localhost but not on the live server.

Following is the backed code where I am checking it.

exports.enableTwoFactorAuthentication = async (req, res) => {
    try {
        let data = req.body;
        console.log("data: ", data)
        const { userId, one_time_password } = data;
        const user = await CRMUser.findById(userId);

        const { tfa_auth_secret_key } = user;
        console.log('user', tfa_auth_secret_key, user)
        console.log("authenticator.check(one_time_password, tfa_auth_secret_key): ",authenticator.check(one_time_password, tfa_auth_secret_key))
        if (!one_time_password || !authenticator.check(one_time_password, tfa_auth_secret_key)) {
            return res.status(200).send({ success: false, message: 'Invalid 2FA Code.'});
        }
        else {
            user.tfa_auth_status = true;
            await user.save();

            return res.status(200).json({ success: true, message: '2FA enabled successfully.', tfa_auth_status: true, secretKey: user.tfa_auth_secret_key, qrImage: user.tfa_auth_qr_image });
        }
    } catch (error) {
        return res.status(500).json({ success: false, message: error.message })
    }
};

Can somebody help me?

@lpavliuk
Copy link

You have to use .verify() method instead of .check() in order to verify the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants