Skip to content

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

@farhanali2325

Description

@farhanali2325

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions