Problem in sending Verification Email with Better Auth

2 days ago 1
ARTICLE AD BOX

I am using Better-auth for authentication But the sendVerification never getting Called I tried lot of things but still the same problem. I am using Brevo for sending emails and it's working correctly I checked it by making manual send-verification Route and it's worked fine for me

import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { nextCookies } from "better-auth/next-js"; import { prisma } from "./prisma"; import { sendVerificationEmail } from "./sendVerificationEmail"; export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", }), plugins: [nextCookies()], emailAndPassword: { enabled: true, requireEmailVerification: true, }, emailVerification: { sendVerificationEmail: async ({ user, url, }) => { await sendVerificationEmail( user.email, user.name || "Volunteer", url ); }, }, }); import { brevo } from "./brevo"; export async function sendVerificationEmail( email: string, userName: string, verificationUrl: string ) { console.log("EMAIL FUNCTION CALLED"); try { console.log("Before Brevo") const response = await brevo.transactionalEmails.sendTransacEmail({ sender: { email: "[email protected]", name: "Volunteer Verification", }, to: [ { email, name: userName, }, ], subject: "Verify your volunteer account", htmlContent: ` <html> <body> <h2> Welcome ${userName} </h2> <p> Thank you for registering as a volunteer. </p> <p> Click below to verify your email: </p> <a href="${verificationUrl}"> Verify Email </a> </body> </html> `, }); console.log("BREVO RESPONSE:", response); } catch (error) { console.log("BREVO ERROR:", error); throw new Error( "Failed to send verification email" ); } }

The email function is never called on Postman I see response generated but the verification email keeps failing.

Read Entire Article