yeojz / otplib

:key: One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator

Home Page:https://otplib.yeojz.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Await & TypeError: Cannot read property 'generate' of undefined

osmenia opened this issue · comments

Hi Team,

This is code, goal is to use await.

const { authenticator } = require("@otplib/core-async");
//const authenticator = require("otplib/authenticator");

const secret = "TE2HGX3CYHA535KR3KX7Q4VLCVJFOQ5E";

(async () => {
  try {
    const token = await authenticator.generate(secret);

    //const isValid = otplib.authenticator.check(token, secret);
    // or
    const isValid = await authenticator.verify({ token, secret });
    console.log(authenticator.timeUsed()); // or totp.timeUsed();
    console.log(authenticator.timeRemaining()); // or totp.timeRemaining();
    console.log(token);
    console.log(isValid);
  } catch (err) {
    // Error possibly thrown by the thirty-two package
    // 'Invalid input - it is not base32 encoded string'
    console.error(err);
  }
})();

I am getting error:
TypeError: Cannot read property 'generate' of undefined

tnx for your help :)