In this article we will list all the custom helper functions that are provided which can be used for creating SBL with dynamic OTPs
Should be importing using
const {getVerificationCode} = require('../mfa/email.js');
/**
* Retrieves a verification code from an email.
*
* @param {string} emailId - The email address to search for verification codes
* @param {Date} receivedAfter - Only search for emails received after this timestamp
* @param {('html'|'text'|'codes')} [place='html'] - Where to look for the verification code:
* - 'html': Search in HTML content
* - 'text': Search in plain text content
* - 'codes': Use built-in AI based code detection
* @param {RegExp} [verificationCodeRegex=/<span[^>]*>(\d+)<\/span>/] - Regular expression to extract the verification code
* @returns {Promise<string|null>} The extracted verification code, or null if not found
* @throws {Error} If an invalid place value is provided
*/
async function getVerificationCode(emailId, receivedAfter, place = "html", verificationCodeRegex = /<span[^>]*>(\d+)<\/span>/)
Should be importing using
const {
generateTOTP
} = require('../mfa/otp.js');
/**
* Generates a Time-based One-Time Password (TOTP) using the provided secret key.
*
* @param {string} secret - The secret key used to generate the TOTP
* @param {number} [digits=6] - The number of digits in the generated TOTP (default: 6)
* @param {number} [period=30] - The time period in seconds for which the TOTP is valid (default: 30)
* @returns {string} The generated TOTP code
*/
function generateTOTP(secret, digits = 6, period = 30)