Skip to content

v0.2 feat: add TOTP / 2FA support via better-auth twoFactor plugin #13

@gitcoder89431

Description

@gitcoder89431

Feature — Two-Factor Authentication (TOTP)

Better Auth ships a first-party twoFactor plugin that handles TOTP (Google Authenticator, Authy, 1Password), backup codes, and trusted devices out of the box. This is a high-value, low-effort addition for v0.2.

What you get for free

  • TOTP QR code generation (totpURI returned on enable)
  • Encrypted secret stored in DB
  • Backup codes (one-time use recovery)
  • Trusted device support (skip 2FA for 30 days on known device)
  • twoFactorEnabled flag on the user object

Server setup

import { twoFactor } from 'better-auth/plugins'

export const auth = betterAuth({
  plugins: [
    twoFactor({
      issuer: 'Vibe Auth',
      totpOptions: { digits: 6, period: 30 },
    }),
  ],
})

Admin panel integration

The existing admin panel already shows user metadata — add a 2FA enabled badge to the users table as a read-only indicator. No new routes needed for MVP.

User settings integration

Add a new "Security" tab section in user settings:

  1. Show current 2FA status
  2. "Enable 2FA" button → shows QR code modal + backup codes
  3. "Disable 2FA" button (requires password confirmation)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions