Better Auth two-factor authentication
Adds the Better Auth twoFactor plugin: TOTP with QR code, email or SMS codes, backup codes, the 2FA step at sign-in, trusted devices, rate limits and encrypted storage. Use when adding MFA to a Better Auth app with email and password accounts.
better-auth-two-factor- Author
- Better Auth
- Source
- better-auth/skills/better-auth/twoFactor @ 20c9e88
- License
- none stated
About this skill
What it does
The skill adds Better Auth's twoFactor plugin and the screens around it. Setup is the server plugin with an issuer, the client plugin with an onTwoFactorRedirect handler, a migration and a check for the twoFactorSecret column on the user table. Turning 2FA on asks for the password and returns a TOTP URI for a QR code (the example uses react-qr-code) plus backup codes; twoFactorEnabled stays false until the first code verifies.
Three second-factor methods are covered. TOTP: 6 or 8 digits, a 30-second period, one period of drift either way. One-time codes by email or SMS through your sendOTP: valid 3 minutes by default, 5 attempts, stored plain, encrypted, hashed or via your own functions. Backup codes: 10 single-use codes, encrypted by default, regenerated with the password, which voids the old set.
At sign-in the response carries twoFactorRedirect: true. The session is removed, a temporary 2FA cookie lives 10 minutes, and a new session is created only after a code is verified. trustDevice: true skips the step for 30 days, renewed on each sign-in. It also notes the built-in limit of 3 requests per 10 seconds on 2FA endpoints, TOTP secrets encrypted with the auth secret and constant-time comparison; disabling 2FA takes the password and drops trusted devices. The folder holds only SKILL.md.
When to use it, and when not
Use it to add MFA to a Better Auth app where users sign in with email and password.
2FA works only for credential accounts, not for OAuth-only users. Passkeys are a separate plugin. Neon's Managed Better Auth lists MFA on its roadmap; there it needs self-managed Better Auth.
How to run it
We do not copy this skill: the author's repository has no licence. Install it from there with the button to the source. The Claude Code plugin in the repository's .claude-plugin/marketplace.json (auth-skills) carries only create-auth and best-practices, so copy the better-auth/twoFactor folder into your agent's skills directory. The name is two-factor-authentication-best-practices:
- Claude Code:
/two-factor-authentication-best-practices, or ask for the skill by name. - Codex:
$two-factor-authentication-best-practices. - Cursor: type
/in the Agent chat and picktwo-factor-authentication-best-practices.
Example: /two-factor-authentication-best-practices Add TOTP with backup codes, a /2fa page after sign-in and trusted devices for 30 days.
How it differs from similar skills
Add authentication with Better Auth can enable 2FA as one feature of the first setup; this skill builds enrolment, the sign-in step and recovery. Better Auth email and password covers the password accounts 2FA depends on. Neon Auth sends MFA to self-managed Better Auth for now. No other skill in our catalog sets up two-factor sign-in.
Install
This skill is not copied to the catalog: the author's repository has no licence text. Install it from there.
Connect through AnyModel API
This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.
AnyModel