Issue with Better-Auth Email Verification

Hey everyone, I'm having an issue with email verification in better-auth. When a user changes their email: The email address gets updated correctly in the database BUT the verification email is not being sent Here's the relevant code:
// auth.js config
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ user, newEmail, url, token }) => {
console.log("sendChangeEmailVerification", user, newEmail, url, token);

await sendEmail({
to: newEmail,
subject: "Vérification d'email",
text: `Cliquez sur ce lien pour vérifier votre nouvelle adresse email: ${url}`,
});
},
},
// ...
}

// action.js (server action)
export async function updateUserEmail(email: string) {
await auth.api.changeEmail({
body: {
newEmail: email,
callbackURL: `/`,
},
headers: await headers(),
})
}
// auth.js config
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ user, newEmail, url, token }) => {
console.log("sendChangeEmailVerification", user, newEmail, url, token);

await sendEmail({
to: newEmail,
subject: "Vérification d'email",
text: `Cliquez sur ce lien pour vérifier votre nouvelle adresse email: ${url}`,
});
},
},
// ...
}

// action.js (server action)
export async function updateUserEmail(email: string) {
await auth.api.changeEmail({
body: {
newEmail: email,
callbackURL: `/`,
},
headers: await headers(),
})
}
The console.log shows nothing when changing email, and no verification email is sent. The email does update in the database though. Any ideas what might be wrong with my implementation?
4 Replies
rhitune
rhitune2d ago
where is send mail codes?
rhitune
rhitune2d ago
also if db updating and mail not sending , its about your mail sending function not better auth
No description
Jïns
JïnsOP16h ago
Yeah but I did this
console.log("sendChangeEmailVerification", user, newEmail, url, token);
console.log("sendChangeEmailVerification", user, newEmail, url, token);
to see if the function get triggered but nothing
rhitune
rhitune11h ago
send your full auth config please

Did you find this page helpful?