Overview
TheOTPConfig interface defines settings for one-time password (OTP) generation, validation, and delivery.
Fields
The number of digits in the generated OTP code.
Valid range is 4-10 digits. Shorter codes are easier to type but less secure. Six digits is the industry standard.
OTP expiration time in seconds.
Maximum number of verification attempts allowed before the OTP becomes invalid.
A function that generates the SMS or email message containing the OTP code.Parameters:Default template:
otp(string): The generated OTP codeappName(string | undefined): Optional application name
Keep messages concise for SMS delivery. Most carriers support 160 characters for a single SMS segment.
Default Configuration
If noOTPConfig is provided, Arraf Auth uses these defaults:
Usage Examples
Custom OTP Length and Expiration
Branded Message Template
High-Security Configuration
Multi-Language Support
Security Considerations
OTP codes are automatically deleted from the database after:
- Successful verification
- Expiration time is reached
- Maximum attempts are exceeded
OTP Verification Flow
- User requests OTP via
/auth/otp/sendendpoint - System generates random code based on
length - Message is formatted using
messageTemplate - Code is sent via configured SMS provider
- User submits code via
/auth/otp/verifyendpoint - System validates code against:
- Expiration time (
expiresIn) - Attempt count (
maxAttempts) - Code correctness
- Expiration time (
- On success, user is authenticated and session is created