pos-be/src/modules/booking-online/helpers/generate-otp.ts

10 lines
289 B
TypeScript

export function generateOtp(digits = 4): number {
if (digits < 1) {
throw new Error('OTP digits must be at least 1');
}
const min = Math.pow(10, digits - 1);
const max = Math.pow(10, digits) - 1;
const otp = Math.floor(Math.random() * (max - min + 1)) + min;
return otp;
}