If you prefer username-based login, see the username plugin. It extends email/password auth with username support.
Enable email and password
SetemailAndPassword.enabled to true in your betterAuth config:
auth.ts
Sign up
CallsignUp.email on the client with the user’s details:
sign-up.ts
Auto sign-in after sign-up
By default, users are automatically signed in after a successful sign-up. Disable this withautoSignIn: false:
auth.ts
Sign in
CallsignIn.email on the client:
sign-in.ts
Server-side sign-in
To authenticate a user on the server, useauth.api:
server.ts
Sign out
CallsignOut on the client:
user-card.ts
Email verification
Provide asendVerificationEmail function in your auth config. Better Auth calls it whenever a verification email needs to be sent:
auth.ts
Require email verification before sign-in
SetrequireEmailVerification: true to block sign-in until the email is confirmed:
auth.ts
sign-in.ts
Trigger verification manually
resend-verification.ts
Password reset
Configure the server
Provide asendResetPassword function in your emailAndPassword config:
auth.ts
Request a password reset
CallrequestPasswordReset on the client with the user’s email:
forgot-password.ts
redirectTo with a ?token=... query parameter. If the token is invalid or expired, the redirect includes ?error=INVALID_TOKEN.
Reset the password
On your reset password page, read the token from the URL and callresetPassword:
reset-password.ts
Change password (authenticated)
Authenticated users can change their password directly:change-password.ts