Skip to content

two-factor-authentication-best-practices

Multi-factor authentication with TOTP, OTP, backup codes, and trusted device management for Better Auth.

— (0 ratings) 37.8K downloads better-auth
$ npx skills add https://github.com/better-auth/skills --skill two-factor-authentication-best-practices

Skills can run code on your computer. Review the source before installing. This listing is community-made and isn't affiliated with Anthropic.

About this skill

Summary

Multi-factor authentication with TOTP, OTP, backup codes, and trusted device management for Better Auth.

  • Supports three verification methods: authenticator apps (TOTP with QR codes), email/SMS codes (OTP), and single-use backup codes
  • Handles complete 2FA sign-in flows with automatic session management, temporary 2FA cookies, and trusted device tracking with configurable expiration
  • Built-in security features including rate limiting (3 requests per 10 seconds), encryption at rest for secrets and backup codes, and constant-time code comparison
  • Configurable code parameters: TOTP digits (6 or 8), OTP validity period, backup code count and length, and custom encryption for OTP storage

Setup

  1. Add twoFactor() plugin to server config with issuer
  2. Add twoFactorClient() plugin to client config
  3. Run npx auth@latest migrate (built-in adapter) or generate + push for Drizzle/Prisma
  4. Verify: check that twoFactorSecret column exists on user table
import { betterAuth } from "better-auth";
import { twoFactor } from "better-auth/plugins";

Installs: 37.8K | GitHub stars: 232 | First seen: Feb 10, 2026

Related skills

New

DevOps & cloud

azure-compliance

Azure compliance scanning, Key Vault expiration auditing, and resource configuration validation.

New • 779.8K
New

Security

entra-app-registration

Microsoft Entra ID app registration, OAuth 2.0 configuration, and MSAL integration for secure application authentication.

New • 779.4K
New

Agent workflows

general-video

Author or edit a custom HyperFrames composition when no specialized workflow fits, or when BRIEF.md sets flow: companion. Use for longer or multi-scene pieces,

New • 662.2K