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]>
8 lines
493 B
TypeScript
8 lines
493 B
TypeScript
// Moderation tests act as people with two-factor sign-in on (sensitive permissions need it); two-factor.test.ts tests
|
|
// the sign-in itself.
|
|
import { eq, schema, type Database } from "@t5de/db";
|
|
|
|
/** Turns two-factor sign-in on for an account, as if they'd set it up. Signing in again would then ask for a code. */
|
|
export const twoFactorOn = (db: Database, username: string) =>
|
|
db.update(schema.user).set({ twoFactorEnabled: true }).where(eq(schema.user.username, username.toLowerCase()));
|