feat: two-factor sign-in, required for sensitive permissions
Better Auth's twoFactor plugin: an authenticator app (TOTP) with 10 backup codes. Turning it on, making new backup codes and turning it off are on the account page, and signing in asks for a code once it's on. Sensitive permissions (product:remove, person:ban, person:role, settings:edit, catalog:suspend, ...) answer 403 two_factor_required without it, API tokens included; the console reminds people who need it. Better Auth's own admin endpoints are closed (404). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
69c55a72fb
commit
d5bc792190
28 files changed
+4365
-62
No files matched your search
+12
-1
@@ -75,7 +75,18 @@ while viewing.
|
||||
Anyone holding a sensitive permission must have two-factor sign-in on (Better Auth's `twoFactor` plugin, TOTP with
|
||||
backup codes): `product:remove`, `person:ban`, `person:role`, `audit:read-sensitive`, `catalog:transfer`,
|
||||
`catalog:suspend`, `import:grant-on-behalf`, `settings:edit`. Without it, those actions answer 403
|
||||
`two_factor_required` and the console asks them to set it up. Giving someone such a role reminds them.
|
||||
`two_factor_required` (with `permission`) and the console asks them to set it up. Giving someone such a role
|
||||
reminds them.
|
||||
|
||||
Built (2026-11-05): `permissions.ts` `sensitive`; `require` throws `TwoFactorRequired` after the permission check,
|
||||
so API tokens are covered too (their owner needs it on). Turning it on is on the account page: the password, then a
|
||||
QR code (and the key as text) for an authenticator app, 10 backup codes, and a code from the app to confirm (Better
|
||||
Auth's `/two-factor/enable` and `/verify-totp`). Signing in then asks for a code from the app or a backup code (each
|
||||
works once). The account page can make new backup codes or turn it off (the password each time). `GET /account`
|
||||
has `twoFactor: {enabled, neededFor}` (the sensitive permissions the person holds anywhere), `GET /console` has
|
||||
`twoFactorNeededFor` (empty once it's on; the console shows a reminder), and people in the console show
|
||||
`twoFactor`. Better Auth's own admin endpoints (`/api/auth/admin/*`) answer 404: bans and roles go through the hub's
|
||||
routes, with the checks and the audit log. No "trust this browser": every sign-in asks.
|
||||
|
||||
## The console
|
||||
|
||||
|
||||
Reference in new issue
Block a user