@@ -3,8 +3,9 @@ import { admin, multiSession, twoFactor } from 'better-auth/plugins'
33import { Resend } from 'resend'
44import { defineServerAuth } from '../../src/runtime/config'
55
6- const resend = new Resend ( process . env . RESEND_API_KEY )
76const from = 'Nuxt Better Auth <onboarding@resend.dev>'
7+ let _resend : Resend
8+ const getResend = ( ) => _resend || ( _resend = new Resend ( process . env . RESEND_API_KEY ) )
89
910export default defineServerAuth ( ( ) => ( {
1011 appName : 'Nuxt Better Auth Playground' ,
@@ -16,22 +17,22 @@ export default defineServerAuth(() => ({
1617 otpOptions : {
1718 async sendOTP ( { user, otp } ) {
1819 console . log ( `[2FA] Sending OTP ${ otp } to ${ user . email } ` )
19- await resend . emails . send ( { from, to : user . email , subject : 'Your 2FA Code' , text : `Your verification code is: ${ otp } ` } )
20+ await getResend ( ) . emails . send ( { from, to : user . email , subject : 'Your 2FA Code' , text : `Your verification code is: ${ otp } ` } )
2021 } ,
2122 } ,
2223 } ) ,
2324 ] ,
2425 emailVerification : {
2526 async sendVerificationEmail ( { user, url } ) {
2627 console . log ( `[Email] Sending verification to ${ user . email } ` )
27- await resend . emails . send ( { from, to : user . email , subject : 'Verify your email' , text : `Click here to verify: ${ url } ` } )
28+ await getResend ( ) . emails . send ( { from, to : user . email , subject : 'Verify your email' , text : `Click here to verify: ${ url } ` } )
2829 } ,
2930 } ,
3031 emailAndPassword : {
3132 enabled : true ,
3233 async sendResetPassword ( { user, url } ) {
3334 console . log ( `[Email] Sending password reset to ${ user . email } ` )
34- await resend . emails . send ( { from, to : user . email , subject : 'Reset your password' , text : `Click here to reset: ${ url } ` } )
35+ await getResend ( ) . emails . send ( { from, to : user . email , subject : 'Reset your password' , text : `Click here to reset: ${ url } ` } )
3536 } ,
3637 } ,
3738} ) )
0 commit comments