authenticator.generate is not a function
osmenia opened this issue · comments
Hi team,
can you pls tell me why i have error:
const authenticator = require("otplib");
const secret = "KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD";
// Alternative:
// const secret = authenticator.generateSecret();
// Note: .generateSecret() is only available for authenticator and not totp/hotp
const token = authenticator.generate(secret);
console.log(token);
Error:
const token = authenticator.generate(secret);
^
TypeError: authenticator.generate is not a function
Versions:
"otplib": "^12.0.1",
nodejs: v12.14.1
you must do something like:
const otplib = require("otplib");
const token = otplib.totp.generate(secret);
Hi, I would like to know how to generate the "secret" here, please.
@mishritha-battiyanda you can generate secret by using this function
const otplib = require("otplib");
let secret = otplib.authenticator.generateSecret();