two-factor-authentication-best-practices

Implement secure two-factor authentication with Better Auth for web and API flows.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides guidance and enforcement rules for implementing secure two-factor authentication (2FA) using Better Auth's twoFactor plugin.

Core Features & Use Cases

  • Enforces 2FA using TOTP, OTP, and backup codes across web and API authentication flows.
  • Supports client- and server-side configuration, trusted devices, and 2FA state management.
  • Demonstrates integration patterns for enabling, verifying, and recovering 2FA with secure defaults.

Quick Start

Install and configure the Better Auth twoFactor plugin in your app and follow the setup steps to enable TOTP, OTP, 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 implement two-factor authentication using Better Auth?

Implement two-factor authentication in Better Auth by configuring the twoFactor plugin to manage TOTP, OTP, and backup codes across web and API authentication flows. You can customize options for TOTP, OTP, backup codes, trusted devices, and 2FA cookie max age.

What is the best way to handle 2FA backup codes and trusted devices?

Handle 2FA backup codes and trusted devices by configuring backupCodeOptions and trustDeviceMaxAge in your authentication setup. This enables secure recovery access and maintains sessions on recognized devices without repeated 2FA verification prompts.

Does Better Auth support TOTP and OTP delivery for server and client integrations?

Better Auth supports TOTP and OTP delivery for both server and client integrations. The twoFactor plugin provides configurable totpOptions and otpOptions to manage verification across front-end and back-end web and API authentication contexts.

What security considerations should I apply for two-factor authentication?

Apply security considerations for two-factor authentication by enforcing encryption and rate limiting within your 2FA flows. The implementation requires secure defaults for enabling, verifying, and recovering 2FA states across credential-based sign-ins.

Can I customize the 2FA cookie max age and trust device duration?

You can customize the 2FA cookie max age and trusted device duration by configuring twoFactorCookieMaxAge and trustDeviceMaxAge. These options control how long a trusted device session remains valid before requiring re-authentication.