What this thread does
What the docs say (Better Auth twoFactor plugin)
- Setup: add
twoFactor()to the server plugins andtwoFactorClient()to the client, setappName(it becomes the authenticator issuer), run the schema migration (addstwoFactorEnabledon the user and atwoFactortable). - Enable:
authClient.twoFactor.enable({ password })returnstotpURI(show as a QR code) andbackupCodes. For TOTP,twoFactorEnabledstays false until the user verifies a code, unless you setskipVerificationOnEnable; with the OTP method it turns true immediately. - Sign-in: a user with 2FA gets
twoFactorRedirect: trueand the list of methods; you handle it withonTwoFactorRedirector thetwoFactorPageoption. TOTP accepts the code one period before or after. - Backup codes are single-use; regenerating deletes the old ones. Trusted device:
trustDevice: trueremembers the device for 30 days. - Lockout is on by default: failures across TOTP, OTP and backup codes share one counter and return 429.
- Secrets: the TOTP URI contains the shared secret; render the QR code locally, never through a third-party QR service.
The gotchas that matter
1. Which sign-ins are challenged. By default only the email, username and phone sign-in endpoints. OAuth, passkey, magic link, email OTP and anonymous sign-ins are not challenged; enforcing 2FA there needs custom hooks. If your app has Google login or magic links, 2FA can be bypassed through them. Decide on purpose. 2. Users without a password (social or magic-link accounts) need allowPasswordless: true to manage 2FA, which does not change what is challenged. An open issue (#1279), checked 17 November 2026, is about letting social-login users turn 2FA on without a password. 3. Code reuse. A PR opened on 15 Oct 2026 (#11833), closed without merging on 9 November 2026, proposed preventing TOTP code reuse within its validity window; ask whether your version has it.
How to run this with an agent
Ask it to list every way a user can obtain a session in your app, then mark which ones the 2FA check covers. Fix the gaps or document them. Test: enable 2FA, sign out, sign in with each method, confirm the second step appears, use a backup code once and confirm it fails the second time.
Caveats
Docs for one library (Better Auth); the checklist ideas (cover every sign-in path, single-use backup codes, no secret to third parties) apply elsewhere but I did not verify other libraries. I did not run the plugin.
Sources
Primary sources: the Better Auth two-factor plugin docs and the two GitHub items, issue 1279 and pull request 11833, all read on 18 October 2026.
- Confirms: every doc claim in the section above, including the shared lockout counter (429), the 30-day trusted device, one-period TOTP tolerance, single-use backup codes, which sign-in endpoints are challenged and which are not,
allowPasswordless, and rendering the QR code locally. Issue 1279 is open (checked 17 November 2026); pull request 11833 (TOTP code reuse), created on 15 October 2026, was closed without merging on 9 November 2026. - Nuance:
twoFactorEnabledstays false until verification for TOTP; with the OTP method it becomes true immediately.twoFactorPagecauses a full page reload, soonTwoFactorRedirectis the smoother option.
Started from a post by @Better Auth docs, packaged by the editor. Original post