Secure core authentication flows
Protect email registration and login from automated abuse.
Better Auth · Const
The Better Auth captcha plugin adds bot protection to selected authentication endpoints. It supports several CAPTCHA providers and validates submitted tokens server-side.
The captcha plugin adds server-side bot verification to selected Better Auth routes. It validates tokens with the configured provider and blocks requests when verification fails or the provider is unavailable.
captcha({ provider, secretKey, endpoints })| Name | Type | Description |
|---|---|---|
provider | string | CAPTCHA provider name, such as cloudflare-turnstile, google-recaptcha, hcaptcha, captchafox, or vercel-botid. |
secretKey | string | Provider secret used for server-side validation; not required for Vercel BotID. |
endpoints | string[] | Optional list of request paths requiring CAPTCHA; supplying it replaces the defaults. |
endpoints replaces the built-in protected routes, so list all routes that should require CAPTCHA.import { betterAuth } from "better-auth";
import { captcha } from "better-auth/plugins";
export const auth = betterAuth({
plugins: [
captcha({
provider: "cloudflare-turnstile",
secretKey: process.env.TURNSTILE_SECRET_KEY!,
}),
],
});Configures the CAPTCHA plugin with Cloudflare Turnstile and a server-side secret key.
Protect email registration and login from automated abuse.
Apply CAPTCHA to authentication routes beyond the default email/password paths.
Use a managed CAPTCHA service while keeping provider validation on the server.
captcha plugin do?captcha is a Better Auth plugin that adds bot protection to authentication endpoints. It validates CAPTCHA tokens server-side for configured routes before allowing the request to proceed.
Follow-up: How are routes selected? By default, email sign-up, email sign-in, and password-reset requests are protected; supplying endpoints replaces that default list.
The required provider selects the CAPTCHA service, while secretKey supplies the credential used for server-side validation. Supported providers include Google reCAPTCHA, Cloudflare Turnstile, hCaptcha, CaptchaFox, and Vercel BotID.
Follow-up: Which provider exception affects configuration? Vercel BotID does not require secretKey, unlike the other listed providers.
The default configuration protects /sign-up/email, /sign-in/email, and /request-password-reset. Other authentication methods require explicitly configuring the endpoints option.
Follow-up: What happens when endpoints is configured? The default routes are no longer implicitly protected, so every desired protected path must be included.
betterAuthpluginsendpointsprovidersecretKey