two-factor-authentication-best-practices

Implement TOTP, OTP, and backup code two-factor authentication with Better Auth.

Updated May 26, 2026
One-click install
npx skills add https://github.com/Albo-Club/albo-os --skill two-factor-authentication-best-practices-albo-club
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: two-factor-authentication-best-practices
Source: https://github.com/Albo-Club/albo-os/tree/main/.agents/skills/two-factor-authentication-best-practices
Command: npx skills add https://github.com/Albo-Club/albo-os --skill two-factor-authentication-best-practices-albo-club

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth, react-qr-code.

What problem does it solve? Adding multi-factor authentication to an application involves many moving parts: TOTP authenticator apps, OTP delivery over email or SMS, backup codes, trusted devices, and secure sign-in flows. This Skill provides complete, working patterns for implementing all of these with Better Auth's twoFactor plugin, including the security configuration details that are easy to get wrong. ## Core Features & Use Cases - TOTP Authenticator Setup: Enable 2FA with password verification, generate TOTP URIs for QR codes, and verify codes with configurable digits and periods. - OTP via Email/SMS: Configure OTP delivery with custom send functions, attempt limits, and encrypted or hashed storage of codes. - Backup Codes & Trusted Devices: Generate, regenerate, and verify single-use backup codes, and remember trusted devices for 30 days. - Use Case: A user signs in with email and password, receives a twoFactorRedirect response, gets routed to a /2fa page, and completes sign-in by entering a code from their authenticator app or a backup code. ## Quick Start Add Better Auth two-factor authentication to my app with TOTP authenticator support, email OTP fallback, and backup codes.

Frequently Asked Questions about two-factor-authentication-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add two-factor authentication with Better Auth?

Add the twoFactor plugin to your Better Auth server config with an issuer, add twoFactorClient to the client config, then run the Better Auth CLI migrate command. Users enable 2FA by calling authClient.twoFactor.enable with their password.

How to set up TOTP authenticator apps in Better Auth?

Call authClient.twoFactor.enable with the user's password to receive a totpURI, render it as a QR code with a library like react-qr-code, then verify the first code with authClient.twoFactor.verifyTotp. Digits and period are configurable via totpOptions.

Does Better Auth 2FA support email or SMS OTP codes?

Yes, the twoFactor plugin supports OTP delivery through a custom sendOTP function in otpOptions, where you integrate your own email or SMS provider. You can configure code validity period, digit count, allowed attempts, and storage mode.

How does the 2FA sign-in flow work with Better Auth?

After calling signIn.email, check for twoFactorRedirect in the response and route the user to a verification page. The session is only created after successful TOTP, OTP, or backup code verification, with a temporary 2FA cookie valid for 10 minutes by default.

Can users enable 2FA on OAuth-only accounts in Better Auth?

No, two-factor authentication can only be enabled for credential accounts using email and password, because enabling and disabling 2FA requires password verification. OAuth-only accounts cannot complete this step.

How are OTP codes and TOTP secrets stored securely?

TOTP secrets are encrypted with the auth secret, backup codes are encrypted by default, and OTP storage is configurable as plain, encrypted, or hashed via the storeOTP option. Verification uses constant-time comparison.