How to use API based providers for sending OTP in Node.js
Published: (February 3, 2026 at 03:16 AM EST)
1 min read
Source: Dev.to
Source: Dev.to
Setup
Install the required library from npm:
npm install auth-verify
Configuration
const AuthVerify = require('auth-verify');
const auth = new AuthVerify();
// Configure the OTP sender
auth.otp.sender({
via: 'email',
service: 'api',
apiService: 'resend', // Change to 'mailgun', 'sendgrid', etc. as needed
apiKey: 'YOUR_API_KEY_HERE'
});
Sending OTP
await auth.otp.send('johndoe@example.com', {
otpLen: 5, // Length of OTP codes (default: 6)
subject: 'Account verification',
text: `Your OTP code is ${auth.otp.code}`
});
Verifying OTP
const valid = await auth.otp.verify('johndoe@example.com', '12345');
if (valid) {
console.log('User verified!');
} else {
console.log('Invalid code!');
}