Email Verification Email is not Sent

I've been trying to add emailVerification to my app for some time, but didn't get it working. My function works well, doesn't have issues when trying it externally from better auth. But when I am trying to make it send the email, it does not work. ( Added prints and it looks like the function isn't called )
emailAndPassword: {
enabled: true,
sendOnSignUp: true,
requireEmailVerification: true,
autoSignInAfterVerification: true,
sendVerificationEmail: async (
{ user, url, token }: { user: any, url: string, token: string },
request: any
) => {
console.log(user.email);
await sendEmail({
to: user?.email,
subject: "Verify your email address",
text: `Click the link to verify your email: ${url}`,
});
},
},
emailAndPassword: {
enabled: true,
sendOnSignUp: true,
requireEmailVerification: true,
autoSignInAfterVerification: true,
sendVerificationEmail: async (
{ user, url, token }: { user: any, url: string, token: string },
request: any
) => {
console.log(user.email);
await sendEmail({
to: user?.email,
subject: "Verify your email address",
text: `Click the link to verify your email: ${url}`,
});
},
},
If anyone could help me I'll be very grateful
Solution:
It looks like the verification email isn’t being sent because the configuration is misplaced. According to Better Auth’s documentation, options like sendOnSignUp and sendVerificationEmail should be defined under the emailVerification configuration rather than inside emailAndPassword. In your snippet, they’re currently under emailAndPassword, so the framework isn’t triggering the verification email on signUp [1], [4]. To fix this, move these options to the emailVerification object in your auth configuration. This should ensure that the email verification process is correctly triggered on signUp. Sources:...
Email | Better Auth
Learn how to use email with Better Auth.
Email & Password | Better Auth
Implementing email and password authentication with Better Auth.
Jump to solution
1 Reply
Solution
Panda
Panda23h ago
It looks like the verification email isn’t being sent because the configuration is misplaced. According to Better Auth’s documentation, options like sendOnSignUp and sendVerificationEmail should be defined under the emailVerification configuration rather than inside emailAndPassword. In your snippet, they’re currently under emailAndPassword, so the framework isn’t triggering the verification email on signUp [1], [4]. To fix this, move these options to the emailVerification object in your auth configuration. This should ensure that the email verification process is correctly triggered on signUp. Sources: [1] Email | Better Auth [4] Email & Password | Better Auth
Email | Better Auth
Learn how to use email with Better Auth.
Email & Password | Better Auth
Implementing email and password authentication with Better Auth.

Did you find this page helpful?