How to Prevent Automatic Resending of Verification Email on Login with requireEmailVerification?

I have a question regarding the requireEmailVerification option. When I set requireEmailVerification: true, the backend correctly returns a 403 response if a non-verified user tries to log in. I handle this on the frontend by showing a verification modal. However, I’ve noticed that BetterAuth also automatically resends the verification email to the user when this happens. What I want: I want the verification email to be sent only when the user explicitly requests it (for example, by clicking a "Resend Verification Email" button in the modal), not automatically when they attempt to log in. Is there a way to disable this automatic resending of the verification email when a non-verified user tries to log in, while still using requireEmailVerification: true? Or do I need to implement custom logic to handle this scenario? Here’s my current configuration:
export const auth = betterAuth({
...
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
},
emailVerification: {
...
sendVerificationEmail: async ({ user, url }) => {
await sendMail(
user.email,
"Verify your email address",
verification_email_html(url)
);
},

},
});
export const auth = betterAuth({
...
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
},
emailVerification: {
...
sendVerificationEmail: async ({ user, url }) => {
await sendMail(
user.email,
"Verify your email address",
verification_email_html(url)
);
},

},
});
And here is my login handler:
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
...
await authClient.signIn.email(
{
email,
password,
},
{
onError: (ctx) => {
setLoading(false);
if (ctx.error && ctx.error.status === 403) {
setShowVerificationModal(true);
} else {
setError(ctx.error?.message || "Sign in failed.");
}
},
onSuccess: () => {
...
},
onRequest: () => ...,
}
);
};
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
...
await authClient.signIn.email(
{
email,
password,
},
{
onError: (ctx) => {
setLoading(false);
if (ctx.error && ctx.error.status === 403) {
setShowVerificationModal(true);
} else {
setError(ctx.error?.message || "Sign in failed.");
}
},
onSuccess: () => {
...
},
onRequest: () => ...,
}
);
};
Is there a configuration option to prevent the automatic sending of the verification email on login, or do I need to implement custom logic to handle this scenario?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?