File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed
Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { prisma } from './prisma'
44import { emailOTP } from 'better-auth/plugins/email-otp'
55import nodemailer from 'nodemailer'
66import { createAuthMiddleware , APIError } from 'better-auth/api'
7+ import { sendEmail } from './email'
78
89const transporter = nodemailer . createTransport ( {
910 service : 'gmail' ,
@@ -28,12 +29,7 @@ export const auth = betterAuth({
2829 plugins : [
2930 emailOTP ( {
3031 async sendVerificationOTP ( { email, otp, type } ) {
31- await transporter . sendMail ( {
32- from : process . env . EMAIL_USER ,
33- to : email ,
34- subject : 'OTP' ,
35- html : `${ otp } ` ,
36- } )
32+ sendEmail ( email , 'OTP' , `${ otp } ` )
3733 } ,
3834 } ) ,
3935 ] ,
Original file line number Diff line number Diff line change 1+ import nodemailer from 'nodemailer'
2+
3+ const transporter = nodemailer . createTransport ( {
4+ service : 'gmail' ,
5+ auth : {
6+ user : process . env . EMAIL_USER ,
7+ pass : process . env . EMAIL_PASS ,
8+ } ,
9+ } )
10+
11+ export const sendEmail = async ( to : string , subject : string , html : string ) => {
12+ try {
13+ await transporter . sendMail ( {
14+ from : process . env . EMAIL_USER ,
15+ to,
16+ subject,
17+ html,
18+ } )
19+ } catch ( error ) {
20+ console . error ( 'Error sending email:' , error )
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments