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!');
}
Back to Blog

Related posts

Read more »

Searcher of lyrics's musics

Overview This application allows users to search for song lyrics by providing the band/artist name and the song title. The graphical interface is built with St...

Zero-configuration support for Koa

Vercel now supports applications, an expressive HTTP middleware framework to make web applications and APIs more enjoyable to write, with zero-configuration.Koa...

What is hybrid developer?

What is a Hybrid Developer? In today’s fast‑evolving tech world, a Hybrid Developer is a software developer skilled in multiple technologies or platforms, enab...