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
@@ -6,6 +6,7 @@ import { createApp } from "../src/app";
|
||||
import { createAuth } from "../src/auth";
|
||||
import { ImvuClient } from "../src/imvu";
|
||||
import { Settings } from "../src/settings";
|
||||
import { twoFactorOn } from "./two-factor";
|
||||
|
||||
const webURL = "http://web.test";
|
||||
let db: Database;
|
||||
@@ -90,6 +91,10 @@ test("only admins open or close registration", async () => {
|
||||
const mod = await signUp("dot");
|
||||
const dot = (await call(admin, "GET", "/api/v1/console/people?waiting=true")).json.people[0];
|
||||
await call(admin, "POST", `/api/v1/console/people/${dot.id}/approve`);
|
||||
// Roles and hub settings are sensitive: two-factor sign-in first.
|
||||
expect((await call(admin, "POST", `/api/v1/console/people/${dot.id}/role`, { role: "moderator" })).json.error).toBe("two_factor_required");
|
||||
expect((await call(admin, "PUT", "/api/v1/console/settings", { registration: "open" })).json.error).toBe("two_factor_required");
|
||||
await twoFactorOn(db, "ada");
|
||||
await call(admin, "POST", `/api/v1/console/people/${dot.id}/role`, { role: "moderator" });
|
||||
expect((await call(mod, "GET", "/api/v1/console/settings")).json).toEqual({ registration: "closed" });
|
||||
expect((await call(mod, "PUT", "/api/v1/console/settings", { registration: "open" })).status).toBe(403);
|
||||
|
||||
Reference in new issue
Block a user