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 + } + }); +}