Send a verification link after signup
New-account verification
Better Auth · Module
sendVerificationEmail is the Better Auth callback used to deliver an email-verification link. Configure it under emailVerification; Better Auth provides the recipient, URL, token, and request context.
Configure emailVerification.sendVerificationEmail with an async callback. Better Auth supplies the user, verification URL, and token when verification begins; the callback passes the URL to your email service. The client can also request another verification email explicitly.
sendVerificationEmail: async ({ user, url, token }, request) => { /* send email */ }| Name | Type | Description |
|---|---|---|
data | object | Object containing user, url, and token. |
data.user | User | The authenticated user, including the destination email address. |
data.url | string | The verification link to send to the user. |
data.token | string | The token used by a custom verification URL. |
request | Request | undefined | Request context supplied to the callback. |
A Promise from the asynchronous email-sending callback; the documentation does not specify a distinct return value.
import { betterAuth } from "better-auth";
export const auth = betterAuth({
emailVerification: {
sendVerificationEmail: async ({ user, url, token }, request) => {
await sendEmail({
to: user.email,
subject: "Verify your email address",
text: `Click the link to verify your email: ${url}`,
});
},
},
});Configure the callback to deliver the verification URL through your email provider.
New-account verification
Required verification
Custom verification flow
User-requested resend
sendVerificationEmail in Better Auth?It is the callback configured under emailVerification that sends the verification message. Better Auth calls it with user, url, token, and the request context.
Follow-up: How can an application request another message? Use the client’s sendVerificationEmail method with the user’s email and an optional callbackURL.
The callback receives the destination URL in url; the example sends that URL in the email text. The token is also available when a custom verification URL is needed.
Follow-up: What should a custom URL preserve? It must retain enough information, such as the verification token, for the verification flow to complete.
If requireEmailVerification is enabled, users must verify their email before logging in. The callback can be triggered during sign-in and can also be invoked manually from the client.
Follow-up: How should the sender handle repeated calls? Make delivery idempotent or otherwise safe to retry, and avoid exposing tokens outside the intended verification link.
emailVerificationsendOnSignUpsendOnSignInrequireEmailVerificationautoSignInAfterVerificationauthClient.sendVerificationEmail