Two Factor Authentication Best Practices

Configure TOTP authenticator apps, send OTP codes via email/SMS, manage backup codes, handle trusted devices, and implement 2FA sign-in flows using Better Auth's twoFactor plugin. Use when users need MFA, multi-factor authentication, authenticator setup, or login security with Better Auth.

227 stars 37 forksSoftware DevelopmentOfficial

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add better-auth/skills --skill two-factor-authentication-best-practices
Manual install
git clone --depth 1 https://github.com/better-auth/skills.git /tmp/skills
mkdir -p ~/.claude/skills
cp -r /tmp/skills/better-auth/twoFactor ~/.claude/skills/two-factor-authentication-best-practices

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

## 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

```ts
import { betterAuth } from "better-auth";
import { twoFactor } from "better-auth/plugins";

export const auth = betterAuth({
  appName: "My App",
  plugins: [
    twoFactor({
      issuer: "My App",
    }),
  ],
});
```

### Client-Side Setup

```ts
import { createAuthClient } from "better-auth/client";
import { twoFactorClient } from "better-auth/client/plugins";

export const authClient = createAuthClient({
  plugins: [
    twoFactorClient({
      onTwoFactorRedirect() {
        window.location.href = "/2fa";
      },
    }),
  ],
});
```

## Enabling 2FA for Users

Requires password verification. Returns TOTP URI (for QR code) and backup codes.

```ts
const enable2FA = async (password: string) => {
  const { data, error } = await authClient.twoFactor.enable({
    password,
  });

  if (data) {
    // data.totpURI — generate a QR code from this
    // data.backupCodes — display to user
  }
};
```

`twoFactorEnabled` is not set to `true` until first TOTP verification succeeds. Override with `skipVerificationOnEnable: true` (not recommended).

## TOTP (Authenticator App)

### Displaying the QR Code
Read the full skill on GitHub

Details

Skill name
two-factor-authentication-best-practices
Path
better-auth/twoFactor/SKILL.md
Repo updated
19 October 2026

FAQ

What does the Two Factor Authentication Best Practices skill do?

Configure TOTP authenticator apps, send OTP codes via email/SMS, manage backup codes, handle trusted devices, and implement 2FA sign-in flows using Better Auth's twoFactor plugin. Use when users need MFA, multi-factor authentication, authenticator setup, or login security with Better Auth.

How do I install the Two Factor Authentication Best Practices skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add better-auth/skills --skill two-factor-authentication-best-practices. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Two Factor Authentication Best Practices popular?

It lives in better-auth/skills, which has 227 GitHub stars and 37 forks, and is included in 1 curated skill list.

Related skills

Better Auth Best Practices

227

better-auth/skills

Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables. Use when users mention Better Auth, betterauth, auth.ts, or need to set up TypeScript authentication with email/password, OAuth, or plugin configuration.

DatabasesIn 1 list37

Create Auth

227

better-auth/skills

Scaffold and implement authentication in TypeScript/JavaScript apps using Better Auth. Detect frameworks, configure database adapters, set up route handlers, add OAuth providers, and create auth UI pages. Use when users want to add login, sign-up, or authentication to a new or existing project with Better Auth.

Software DevelopmentIn 1 list37

Behat Skill

386

LambdaTest/agent-skills

Generates Behat BDD tests for PHP with Gherkin feature files and MinkContext for browser testing. Use when user mentions "Behat", "PHP BDD", "Mink", "behat.yml". Triggers on: "Behat", "PHP BDD", "Mink", "behat.yml", "FeatureContext PHP".

Software DevelopmentIn 1 list76

Temporal Developer

236

temporalio/skill-temporal-developer

Develop, debug, and manage Temporal applications across Python, TypeScript, Go, Java, .NET, Ruby, and Rust. Use when the user is building workflows, activities, workers, or background job queues with a Temporal SDK, debugging issues like non-determinism errors, stuck workflows, or activity retries, using Temporal CLI, Temporal Server, or Temporal Cloud, running Temporal with Docker Compose, or working with durable execution concepts like signals, queries, heartbeats, versioning, continue-as-new, child workflows, or saga patterns. Also use when the user mentions "run a Temporal workflow from th

Software Development33

Behave Skill

386

LambdaTest/agent-skills

Generates Behave BDD tests for Python with Gherkin feature files and step implementations. Use when user mentions "Behave", "Python BDD", "Python Gherkin". Triggers on: "Behave", "Python BDD", "behave test", "Python feature file".

Software DevelopmentIn 1 list76

Codeception Skill

386

LambdaTest/agent-skills

Generates Codeception tests in PHP covering acceptance, functional, and unit testing. BDD-style with Actor pattern. Use when user mentions "Codeception", "$I->amOnPage", "$I->see", "Cest". Triggers on: "Codeception", "$I->amOnPage", "AcceptanceTester", "Codeception PHP", "Cest".

Software DevelopmentIn 1 list76

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.