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

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

Open
osmenia opened this issue Feb 20, 2021 · 0 comments
Open

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

osmenia opened this issue Feb 20, 2021 · 0 comments

Comments

@osmenia
Copy link

osmenia commented Feb 20, 2021

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 :)

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

1 participant