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
This commit is contained in:
NeilClack
2026-07-07 08:54:47 -05:00
parent a72b65be95
commit ba83c48b9e
2 changed files with 20 additions and 7 deletions
+5 -7
View File
@@ -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
});
}
},