DOCS / FEATURES
Two-factor authentication
With two-factor turned on, a password or magic-link sign-in also asks for a TOTP code (RFC 6238) or a single-use recovery code. Any authenticator app works (Google Authenticator, 1Password, Authy, and friends).
The code lives in api/src/auth/totp.rs (HTTP surface and helpers) and
api/src/auth/service.rs (rules). The UI is
web/src/features/account/TwoFactorPanel.tsx. A passkey
sign-in skips the code, since the passkey is already two factors.
Enrolment is two steps
Setup:
POST /api/users/me/2fa/setupwith{"password"}(required when the account has a password, skipped for OAuth-only accounts). Stores a pending secret and returns:json { "secret": "JBSWY3DP...", "otpauth_url": "otpauth://totp/LaunchCrate:...", "qr_svg": "<svg ...>" }Nothing is enforced yet. Running setup again replaces the pending secret.
Enable:
POST /api/users/me/2fa/enablewith{"code"}. The first valid code proves the authenticator works. Two-factor turns on, and the response carries ten recovery codes, shown exactly once:json { "recovery_codes": ["7KQ2M-XW9PD", "..."] }
GET /api/users/me/2fa returns {"enabled": bool}.
The SPA renders qr_svg as an <img> with a data: URI (allowed by the
CSP), never through innerHTML.
Signing in
For a password login on a two-factor account, POST /api/auth/login
doesn't issue credentials. It answers (and so does
POST /api/auth/magic-link/verify for a magic-link sign-in):
{ "two_factor_required": true, "challenge_token": "..." }The client then posts the code with the challenge:
curl -X POST localhost:8787/api/auth/2fa \
-H 'content-type: application/json' \
-d '{"challenge_token":"...","code":"123456","mode":"session"}'[ full guide ]
The rest of this guide comes with the repo.
- Codes are single-use
- Disabling
- Inside an impersonation
- Storage and hardening