Passwordless sign-in
Users authenticate without entering a password by receiving a short-lived code by email.
Better Auth · Function
Better Auth’s Email OTP plugin enables email-code sign-in, email verification, and password resets. Configure a delivery callback, then use the client plugin to request and consume OTPs.
The plugin generates one-time codes and supports passwordless sign-in, email verification, and password reset. Your configuration supplies sendVerificationOTP, which receives the destination address, code, and flow type so the application can deliver the code; the client plugin exposes the corresponding OTP operations.
emailOTP(options)| Name | Type | Description |
|---|---|---|
options | EmailOTPOptions | Configuration object for the Email OTP plugin, including sendVerificationOTP and OTP options. |
An Email OTP plugin configured for a Better Auth instance.
import { betterAuth } from "better-auth"
import { emailOTP } from "better-auth/plugins"
export const auth = betterAuth({
plugins: [
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
console.log({ email, otp, type })
}
})
]
})Configure the plugin and replace the logging body with delivery through your email provider.
Users authenticate without entering a password by receiving a short-lived code by email.
New users confirm control of their email address through a code instead of a link.
Users recover access by receiving a code and setting a new password.
The Email OTP plugin supports three flows: sign-in, email verification, and password reset. It generates the code and invokes sendVerificationOTP with email, otp, and type so the application can deliver it.
Follow-up: How would you replace link-based verification? Set overrideDefaultEmailVerification to true in the plugin options.
The client setup uses emailOTPClient in createAuthClient. A sign-in flow first calls sendVerificationOtp, then completes authentication with signIn.emailOtp after the user supplies the code.
Follow-up: How would you initiate password recovery? Call emailOtp.requestPasswordReset to send a forget-password code.
The server callback receives a type identifying the operation, including sign-in, email-verification, or password reset. The application can select an appropriate message or template for each type before sending the OTP.
Follow-up: What configuration controls code lifetime? Use expiresIn, whose value is specified in seconds.
emailOTPClientsendVerificationOtpsignIn.emailOtpemailOtp.requestPasswordResetoverrideDefaultEmailVerificationexpiresIn