two-factor-authentication-best-practices

Configure Better Auth's twoFactor plugin for TOTP, OTP, and backup codes.

206|30|Updated Oct 20, 2025
One-click install
npx skills add https://github.com/better-auth/skills --skill two-factor-authentication-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: two-factor-authentication-best-practices
Source: https://github.com/better-auth/skills/tree/main/better-auth/twoFactor
Command: npx skills add https://github.com/better-auth/skills --skill two-factor-authentication-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide provides concrete guidance and enforcement rules for implementing secure two-factor authentication (2FA) using Better Auth's twoFactor plugin, reducing the risk of unauthorized access.

Core Features & Use Cases

  • Guidance on configuring the twoFactor plugin with a clear issuer and app name.
  • Comprehensive coverage of enabling 2FA for users, verifying codes via TOTP, OTP, and backup codes, and managing trusted devices.
  • Real-world scenario: securing a production app's authentication flow by layering TOTP-based 2FA, email OTPs, and backup codes, with a reliable verification and recovery process.

Quick Start

Enable the twoFactor plugin in your Better Auth setup and run the migration to create the required 2FA fields.

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 implement two-factor authentication using Better Auth?

Implement two-factor authentication by enabling the twoFactor plugin in Better Auth, running the migration to add required fields, and configuring TOTP, OTP, and backup codes for secure user sign-in flows.

What is the best way to configure TOTP and backup codes for 2FA?

The best way to configure TOTP and backup codes is to use the twoFactor plugin to enforce secure storage, rate limiting, and robust recovery options, ensuring a reliable verification process for users.

Does Better Auth support trusted devices and email OTP for two-factor authentication?

Yes, Better Auth supports trusted devices and email OTP, allowing you to layer TOTP-based 2FA and OTPs into your production app's authentication flow with a comprehensive verification and recovery process.

How do I enable 2FA for users in a Better Auth application?

Enable 2FA for users by configuring the twoFactor plugin across both client and server, applying credential-based enablement, and verifying codes via TOTP, OTP, or backup codes during the sign-in flow.

Why do I need rate limiting and secure storage for two-factor authentication?

Rate limiting and secure storage are required for two-factor authentication to prevent brute-force attacks on verification codes and ensure backup codes and TOTP secrets are protected against unauthorized access.

Can I use backup codes for account recovery when 2FA is enabled?

Yes, backup codes can be used for account recovery when 2FA is enabled, providing a robust recovery option through the twoFactor plugin if users lose access to their primary TOTP or OTP device.