Node.js에서 OTP 전송을 위한 API 기반 제공업체 사용 방법
발행: (2026년 2월 3일 오후 05:16 GMT+9)
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!');
}