two-factor-authentication-best-practices

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

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/nashirabbash/autorepychatbot --skill two-factor-authentication-best-practices-nashirabbash
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: two-factor-authentication-best-practices
Source: https://github.com/nashirabbash/autorepychatbot/tree/main/.agents/skills/two-factor-authentication-best-practices
Command: npx skills add https://github.com/nashirabbash/autorepychatbot --skill two-factor-authentication-best-practices-nashirabbash

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Two-factor authentication setup and management can be tedious and error-prone for teams and users. This skill provides a complete guide for integrating MFA using Better Auth's twoFactor plugin, including server and client setup, user enrollment, and secure flows.

Core Features & Use Cases

  • TOTP-based authenticator setup and verification
  • OTP delivery via email/SMS with retry and security considerations
  • Backup codes management and recovery
  • Trusted devices and session security
  • End-to-end sign-in flow with 2FA redirection

Quick Start

Add twoFactor() to your server config with an issuer and enable client-side twoFactorClient(), then migrate and verify that users can enroll and complete 2FA during sign-in.

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 set up two-factor authentication with TOTP and backup codes?

Set up two-factor authentication by adding the twoFactor() plugin to your server config and enabling twoFactorClient() on the client. This handles TOTP enrollment, backup code generation, and secure sign-in redirection.

What is the best way to handle MFA recovery and trusted devices?

The best way to handle MFA recovery is using generated backup codes and marking trusted devices. This allows users to regain access securely without a second factor while maintaining session security across recognized devices.

Can I send OTP codes via email and SMS for multi-factor authentication?

Yes, you can send OTP codes via email and SMS. The twoFactor plugin supports OTP delivery with built-in retry mechanisms and security considerations to ensure reliable multi-factor authentication verification.

How do I implement a 2FA sign-in flow that redirects users for verification?

Implement a 2FA sign-in flow by configuring twoFactorClient() to intercept standard logins, prompt for the TOTP or OTP code, and verify the submission before granting full session access. This requires server and client configuration.

Do I need to run database migrations to enable two-factor authentication?

Yes, you need to run database migrations to enable two-factor authentication. Migrations securely store user secrets, backup codes, and trusted device records required by the twoFactor plugin for enrollment and recovery.