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

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();