From ba83c48b9e3b47846e9c5da2cd3480559ecf2333 Mon Sep 17 00:00:00 2001 From: NeilClack Date: Tue, 7 Jul 2026 08:54:47 -0500 Subject: [PATCH] auth: extract reusable sendVerificationEmail utility, enable sendOnSignUp - Create src/lib/server/email-verification.ts with exported utility function - Use it in auth.ts sendVerificationEmail callback - Enable sendOnSignUp so verification email is sent on registration --- src/lib/auth.ts | 12 +++++------- src/lib/server/email-verification.ts | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 src/lib/server/email-verification.ts diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 53b8add..c375149 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -4,6 +4,7 @@ import { prisma } from '$lib/db'; import { sveltekitCookies } from 'better-auth/svelte-kit'; import { getRequestEvent } from '$app/server'; import { sendMail } from './server/resend'; +import { sendVerificationEmail } from './server/email-verification'; export const auth = betterAuth({ baseURL: process.env.BETTER_AUTH_URL, @@ -11,14 +12,11 @@ export const auth = betterAuth({ provider: 'postgresql' }), emailVerification: { + sendOnSignUp: true, sendVerificationEmail: async ({ user, url }) => { - void sendMail({ - to: user.email, - templateId: 'email-verification-email', - data: { - target_email_address: user.email, - verification_link: url - } + void sendVerificationEmail({ + email: user.email, + verificationUrl: url }); } }, diff --git a/src/lib/server/email-verification.ts b/src/lib/server/email-verification.ts new file mode 100644 index 0000000..0e74479 --- /dev/null +++ b/src/lib/server/email-verification.ts @@ -0,0 +1,15 @@ +import { sendMail } from './resend'; + +export async function sendVerificationEmail(options: { + email: string; + verificationUrl: string; +}) { + await sendMail({ + to: options.email, + templateId: 'email-verification-email', + data: { + target_email_address: options.email, + verification_link: options.verificationUrl + } + }); +}