forked from ttc/micro-service-api
-web-service
This commit is contained in:
17
exthernal-accountingwep-api/src/services/otpservice.js
Normal file
17
exthernal-accountingwep-api/src/services/otpservice.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { generateOTP } from '../utils/otp.js'
|
||||
import { sendMockOtpMail } from '../utils/mailer.js'
|
||||
import { saveOtp, verifyOtp, removeOtp } from '../utils/redis.js'
|
||||
import { sendError } from '../utils/response.js'
|
||||
|
||||
export class OtpService {
|
||||
async sendOtp(email) {
|
||||
try {
|
||||
const otp = generateOTP()
|
||||
await saveOtp(email, otp)
|
||||
await sendMockOtpMail(email, otp)
|
||||
return { email, otp}
|
||||
} catch (error) {
|
||||
return sendError('ไม่สามารถส่ง OTP ได้', 'Failed to send OTP')
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user