const otplib = require('otplib');
// The secret from your otpauth URL
const secret = 'XXXXXXXXX';
// Set up the algorithm and other options globally
otplib.authenticator.options = {
algorithm: 'sha1', // Use SHA1 algorithm
digits: 6, // Number of digits in the OTP
step: 30 // Period in seconds (default is 30 seconds)
};
/**
- Function to generate a TOTP based on a provided secret.
- @param {string} secret - The shared secret key.
- @returns {string} - The generated OTP.
*/
function generateTOTP() {
return otplib.authenticator.generate(secret);
}
module.exports = {
generateTOTP
};
I am using this code to generate TOTP some sometimes getting validate TOTP and sometime not getting it verified