如何在 Node.js 中使用基于 API 的提供商发送 OTP

发布: (2026年2月3日 GMT+8 16:16)
1 min read
原文: Dev.to

Source: Dev.to

设置

从 npm 安装所需的库:

npm install auth-verify

配置

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'
});

发送 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}`
});

验证 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

相关文章

阅读更多 »

歌词搜索者的音乐

概述 本应用允许用户通过提供乐队/艺术家名称和歌曲标题来搜索歌词。图形界面使用 St... 构建。

Koa 的零配置支持

Vercel 现在支持 applications,一个富有表现力的 HTTP 中间件框架,使编写 Web 应用和 API 更加愉快,且无需配置。Koa…

什么是混合开发者?

什么是Hybrid Developer?在当今快速发展的技术世界中,Hybrid Developer是一名精通多种技术或平台的软件开发人员,能够……