Skip to content

Commit 55bc61c

Browse files
committed
fix(playground): lazy resend init, rename wrangler app
1 parent a1cc6b4 commit 55bc61c

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

playground/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default defineNuxtConfig({
3434
'/two-factor/otp': { auth: false },
3535
},
3636

37-
nitro: { alias: { '@react-email/render': 'unenv/runtime/mock/empty' } },
37+
nitro: { virtual: { '#react-email-mock': 'export const render = () => ""' }, alias: { '@react-email/render': '#react-email-mock' } },
3838

3939
compatibilityDate: '2025-01-01',
4040
})

playground/server/auth.config.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { admin, multiSession, twoFactor } from 'better-auth/plugins'
33
import { Resend } from 'resend'
44
import { defineServerAuth } from '../../src/runtime/config'
55

6-
const resend = new Resend(process.env.RESEND_API_KEY)
76
const from = 'Nuxt Better Auth <onboarding@resend.dev>'
7+
let _resend: Resend
8+
const getResend = () => _resend || (_resend = new Resend(process.env.RESEND_API_KEY))
89

910
export 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
}))

playground/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "nuxt-better-auth-playground"
1+
name = "nuxt-better-auth-demo"
22
main = ".output/server/index.mjs"
33
compatibility_date = "2025-01-01"
44
compatibility_flags = [ "nodejs_compat" ]

0 commit comments

Comments
 (0)