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:
+5
-7
@@ -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
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user