From eca188491801df61a7f8215eb0a260affe217a12 Mon Sep 17 00:00:00 2001 From: dhkatz Date: Fri, 6 Nov 2026 03:23:02 +0000 Subject: [PATCH] feat: two-factor sign-in, required for sensitive permissions (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 3d (docs/design.md): two-factor sign-in, required for sensitive permissions. - **Sign-in:** Better Auth's `twoFactor` plugin, using an authenticator app (TOTP) with 10 backup codes. Once it's on, signing in asks for a code from the app or a backup code, and each backup code works once. - **Account page:** a new Two-Factor Sign-In card. - To turn it on: enter your password, scan the QR code (the key is also shown as text), keep the backup codes, and confirm with a code. - Once it's on, you can make new backup codes or turn it off; both ask for the password. - If you hold sensitive permissions, the card lists the ones that need it. - **Enforcement:** the sensitive permissions are `product:remove`, `person:ban`, `person:role`, `audit:read-sensitive`, `catalog:transfer`, `catalog:suspend`, `import:grant-on-behalf` and `settings:edit` (`permissions.ts` `sensitive`). Without two-factor on, they answer 403 `two_factor_required`, and API tokens get the same check through their owner. - Routes guarded only by the moderator check now also check the permission: removing products, ban and unban, roles, and settings. - **Console:** a reminder on every console page while two-factor is needed. The People list notes staff without two-factor, and each person's page shows "two-factor on". - **Closed Better Auth admin endpoints:** `/api/auth/admin/*` now answers 404. Admins could have used these endpoints to ban people or change roles without the check or the audit log. - **Tests:** a new end-to-end test, `test/two-factor.test.ts`. Moderation tests turn two-factor on for their accounts directly (`test/two-factor.ts`). All 57 API tests pass, and type checks pass. - **Checked on the scratch hub through the website:** - turning it on with a real code - the console reminder appearing and disappearing - signing in again needing a code - a Ban form while two-factor is off showing "Turn on two-factor sign-in on your account page first." - **Not checked in a browser:** the QR and sign-in code screens. - **Dependency:** `uqr` draws the QR code; it has no dependencies of its own. Phase 3d (docs/design.md): two-factor sign-in, required for sensitive permissions. - **Sign-in:** Better Auth's `twoFactor` plugin, using an authenticator app (TOTP) with 10 backup codes. Once it's on, signing in asks for a code from the app or a backup code, and each backup code works once. - **Account page:** a new Two-Factor Sign-In card. - To turn it on: enter your password, scan the QR code (the key is also shown as text), keep the backup codes, and confirm with a code. - Once it's on, you can make new backup codes or turn it off; both ask for the password. - If you hold sensitive permissions, the card lists the ones that need it. - **Enforcement:** the sensitive permissions are `product:remove`, `person:ban`, `person:role`, `audit:read-sensitive`, `catalog:transfer`, `catalog:suspend`, `import:grant-on-behalf` and `settings:edit` (`permissions.ts` `sensitive`). Without two-factor on, they answer 403 `two_factor_required`, and API tokens get the same check through their owner. - Routes guarded only by the moderator check now also check the permission: removing products, ban and unban, roles, and settings. - **Console:** a reminder on every console page while two-factor is needed. The People list notes staff without two-factor, and each person's page shows "two-factor on". - **Closed Better Auth admin endpoints:** `/api/auth/admin/*` now answers 404. Admins could have used these endpoints to ban people or change roles without the check or the audit log. - **Tests:** a new end-to-end test, `test/two-factor.test.ts`. Moderation tests turn two-factor on for their accounts directly (`test/two-factor.ts`). All 57 API tests pass, and type checks pass. - **Checked on the scratch hub through the website:** - turning it on with a real code - the console reminder appearing and disappearing - signing in again needing a code - a Ban form while two-factor is off showing "Turn on two-factor sign-in on your account page first." - **Not checked in a browser:** the QR and sign-in code screens. - **Dependency:** `uqr` draws the QR code; it has no dependencies of its own. Later: auditing when two-factor is turned on or off, and an optional "trust this browser". 🤖 Generated with [Claude Code](https://claude.com/claude-code) Later: auditing when two-factor is turned on or off, and an optional "trust this browser". 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: dhkatz --- apps/api/src/app.ts | 39 +- apps/api/src/auth.ts | 7 +- apps/api/src/permissions.ts | 25 +- apps/api/test/blocks.test.ts | 2 + apps/api/test/cases.test.ts | 2 + apps/api/test/catalogs.test.ts | 2 + apps/api/test/hub.test.ts | 2 + apps/api/test/products.test.ts | 2 + apps/api/test/registration.test.ts | 5 + apps/api/test/tokens.test.ts | 2 + apps/api/test/two-factor.test.ts | 132 + apps/api/test/two-factor.ts | 7 + apps/web/app/account/page.tsx | 3 + apps/web/app/account/two-factor-card.tsx | 291 ++ apps/web/app/console/console-nav.tsx | 62 +- apps/web/app/console/people/[id]/page.tsx | 1 + apps/web/app/console/people/page.tsx | 7 +- apps/web/app/signin/signin-form.tsx | 149 +- apps/web/lib/auth-client.ts | 8 +- apps/web/package.json | 3 +- bun.lock | 7 +- docs/api.md | 3 +- docs/console.md | 13 +- docs/design.md | 4 +- packages/db/drizzle/0015_two_factor.sql | 14 + packages/db/drizzle/meta/0015_snapshot.json | 3609 +++++++++++++++++++ packages/db/drizzle/meta/_journal.json | 7 + packages/db/src/schema.ts | 19 + 28 files changed, 4365 insertions(+), 62 deletions(-) create mode 100644 apps/api/test/two-factor.test.ts create mode 100644 apps/api/test/two-factor.ts create mode 100644 apps/web/app/account/two-factor-card.tsx create mode 100644 packages/db/drizzle/0015_two_factor.sql create mode 100644 packages/db/drizzle/meta/0015_snapshot.json diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts index d335439..f5bb58e 100644 --- a/apps/api/src/app.ts +++ b/apps/api/src/app.ts @@ -48,7 +48,17 @@ import { Catalogs } from "./catalogs"; import { appealable, caseKinds, Cases, type Case, type CaseKind } from "./cases"; import { Notifications } from "./notifications"; import { maxGrants, maxTokenDays, tokenPrefix, Tokens } from "./tokens"; -import { assignableCatalogRoles, Forbidden, hubScope, Permissions, roles as roleBundles, type Scope } from "./permissions"; +import { + assignableCatalogRoles, + Forbidden, + hubScope, + Permissions, + roles as roleBundles, + sensitive, + TwoFactorRequired, + type Permission, + type Scope, +} from "./permissions"; const { user, session, imvuLink, linkChallenge, audit, hostedRoom, catalog, product, hosting } = schema; @@ -211,6 +221,7 @@ export function createApp({ banned: p.banned === true, banReason: p.banReason ?? "", approved: p.approved, + twoFactor: p.twoFactorEnabled, }); /** A person's picture, for the website's header: their first linked IMVU account's avatar picture (null if none, @@ -291,10 +302,21 @@ export function createApp({ await perms.require(who, permission, scope); } catch (e) { if (e instanceof Forbidden) throw forbiddenProblem(e); + if (e instanceof TwoFactorRequired) + throw new Problem(403, "two_factor_required", e.message, { permission: e.permission }); throw e; } }; + /** The sensitive permissions a person holds anywhere (hub-wide, or on a catalog's team): they need two-factor + * sign-in for those. */ + const sensitiveHeld = async (me: Person): Promise => { + const held = new Set([...perms.hub(me)].filter((p) => sensitive.includes(p))); + for (const c of await perms.teamCatalogs(me.id)) + for (const p of await perms.at(me, catalogScope(c))) if (sensitive.includes(p)) held.add(p); + return sensitive.filter((p) => held.has(p)); + }; + /** Who's online that viewer may see: accounts showing their presence (moderators see all). */ const visibleOnline = async (viewer: Person | undefined) => { const online = realtime.online(); @@ -941,6 +963,8 @@ export function createApp({ })), computers: computers?.n ?? 0, canLink: links.length < me.linkCap, + // Two-factor sign-in: on or off, and what needs it (sensitive permissions the person holds). + twoFactor: { enabled: me.twoFactorEnabled, neededFor: await sensitiveHeld(me) }, }; }, { signedIn: true }, @@ -2050,6 +2074,7 @@ export function createApp({ .post( "/products/:id/remove", async ({ me, params, body }) => { + await need(me, "product:remove", hubScope); const removed = await productCall(() => products.removeByModeration(params.id, body.reason.trim())); await audited(me, "product.remove", params.id, { reason: body.reason.trim() }, { product: params.id, @@ -2678,6 +2703,8 @@ export function createApp({ return { sections, mine: { products: scope.products.length, catalogs: scope.catalogs.length, rooms: scope.rooms.length }, + // Sensitive permissions held without two-factor sign-in: the console asks them to turn it on. + twoFactorNeededFor: me.twoFactorEnabled ? [] : await sensitiveHeld(me), todo: { drafts: scope.products.length ? await products.draftCount(me.id) : 0, cases: await cases.openToDecide(me), @@ -2787,6 +2814,7 @@ export function createApp({ "/console/settings", async ({ me, body }) => { if (me.role !== "admin") throw new Problem(403, "forbidden", "Only admins can change the hub's settings."); + await need(me, "settings:edit", hubScope); const from = await settings.registration(); await settings.setRegistration(body.registration); if (from !== body.registration) await audited(me, "hub.registration", body.registration, { from }); @@ -2823,6 +2851,7 @@ export function createApp({ .post( "/console/people/:id/ban", async ({ me, params, body }) => { + await need(me, "person:ban", hubScope); const p = await personById(params.id); if (p.id === me.id) throw new Problem(400, "invalid", "You can't ban yourself."); if (isModerator(p) && me.role !== "admin") throw new Problem(403, "forbidden", "Only admins can ban moderators."); @@ -2837,6 +2866,7 @@ export function createApp({ .post( "/console/people/:id/unban", async ({ me, params }) => { + await need(me, "person:ban", hubScope); const p = await personById(params.id); const [updated] = await db.update(user).set({ banned: false, banReason: null }).where(eq(user.id, p.id)).returning(); await audited(me, "person.unban", p.username ?? p.id); @@ -2848,6 +2878,7 @@ export function createApp({ "/console/people/:id/role", async ({ me, params, body }) => { if (me.role !== "admin") throw new Problem(403, "forbidden", "Only admins can change roles."); + await need(me, "person:role", hubScope); const p = await personById(params.id); if (p.id === me.id) throw new Problem(400, "invalid", "Another admin has to change your role."); const [updated] = await db.update(user).set({ role: body.role }).where(eq(user.id, p.id)).returning(); @@ -2912,6 +2943,12 @@ export function createApp({ }); const app = new Elysia() + // Better Auth's admin endpoints (bans, roles, impersonation) aren't used: the hub's own routes do those, with + // permission and two-factor checks and the audit log. + .all("/api/auth/admin/*", ({ set }) => { + set.status = 404; + return { error: "not_found", message: "Not found." }; + }) .all("/api/auth/*", ({ request }) => auth.handler(request)) .get("/.well-known/jwks.json", async () => auth.api.getJwks()) .get("/.well-known/t5de-keys.json", async () => signer.jwks()) diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts index 65dae89..474c45d 100644 --- a/apps/api/src/auth.ts +++ b/apps/api/src/auth.ts @@ -1,9 +1,9 @@ // Accounts, sessions and proxy sign-in, by Better Auth: email and password with usernames, roles and bans (admin), // device sign-in for T5DE's proxy (RFC 8628), bearer tokens for the proxy's requests, and JWTs with published keys -// (for catalogs later). +// (for catalogs later), and two-factor sign-in (an authenticator app, with backup codes). import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; -import { admin, bearer, deviceAuthorization, jwt, username } from "better-auth/plugins"; +import { admin, bearer, deviceAuthorization, jwt, twoFactor, username } from "better-auth/plugins"; import { count, schema, type Database } from "@t5de/db"; import { Settings } from "./settings"; @@ -69,6 +69,9 @@ export function createAuth(db: Database, config: AuthConfig) { validateClient: (clientId) => clientId === proxyClientID, }), bearer(), + // Once it's on, signing in asks for a code from the app (or a backup code). The hub's own routes require it for + // sensitive permissions (permissions.ts `sensitive`). + twoFactor({ issuer: "T5DE", backupCodeOptions: { amount: 10, length: 10 } }), jwt({ jwks: { keyPairConfig: { alg: "EdDSA", crv: "Ed25519" } } }), ], }); diff --git a/apps/api/src/permissions.ts b/apps/api/src/permissions.ts index 66fda33..e896951 100644 --- a/apps/api/src/permissions.ts +++ b/apps/api/src/permissions.ts @@ -60,6 +60,18 @@ export const permissions = [ export type Permission = (typeof permissions)[number]; +/** Permissions that need two-factor sign-in on: without it, using them answers 403 `two_factor_required`. */ +export const sensitive: readonly Permission[] = [ + "product:remove", + "person:ban", + "person:role", + "audit:read-sensitive", + "catalog:transfer", + "catalog:suspend", + "import:grant-on-behalf", + "settings:edit", +]; + /** Where a permission applies. The hub covers everything. */ export type Scope = { type: "hub" } | { type: "catalog"; id: string } | { type: "product"; id: string }; @@ -144,7 +156,7 @@ export type RoleId = keyof typeof roles; export const assignableCatalogRoles = ["catalog-operator"] as const; /** A person, as the check needs them. Signed in with an API token, only what it grants too (the intersection). */ -export type Who = { id: string; role: string; token?: { id: string; name: string; grants: TokenGrant[] } }; +export type Who = { id: string; role: string; twoFactorEnabled?: boolean; token?: { id: string; name: string; grants: TokenGrant[] } }; /** Whether a token (if any) grants a permission at a scope: granted there, or hub-wide. */ export function granted(who: Who | undefined, permission: Permission, scope: Scope): boolean { @@ -156,6 +168,13 @@ export function granted(who: Who | undefined, permission: Permission, scope: Sco ); } +/** Thrown when a sensitive permission is held but two-factor sign-in is off. */ +export class TwoFactorRequired extends Error { + constructor(readonly permission: Permission) { + super("Turn on two-factor sign-in on your account page first."); + } +} + /** Thrown when a permission is missing; the API answers 403 with what was missing. */ export class Forbidden extends Error { constructor( @@ -211,9 +230,11 @@ export class Permissions { return (await this.at(who, scope)).has(permission); } - /** Throws Forbidden unless the person holds the permission at the scope. */ + /** Throws Forbidden unless the person holds the permission at the scope, and TwoFactorRequired if it's sensitive + * and they haven't turned two-factor sign-in on. */ async require(who: Who | undefined, permission: Permission, scope: Scope): Promise { if (!(await this.can(who, permission, scope))) throw new Forbidden(permission, scope); + if (sensitive.includes(permission) && !who?.twoFactorEnabled) throw new TwoFactorRequired(permission); } /** May `who` give (or take away) `role` at `scope`? Only if they hold every permission in it there. */ diff --git a/apps/api/test/blocks.test.ts b/apps/api/test/blocks.test.ts index ef82c35..e52777a 100644 --- a/apps/api/test/blocks.test.ts +++ b/apps/api/test/blocks.test.ts @@ -4,6 +4,7 @@ import { afterAll, beforeAll, expect, test } from "bun:test"; import { openDatabase, type Database } from "@t5de/db"; import { createApp } from "../src/app"; import { createAuth } from "../src/auth"; +import { twoFactorOn } from "./two-factor"; import { ImvuClient, type ImvuUser } from "../src/imvu"; const webURL = "http://web.test"; @@ -75,6 +76,7 @@ async function person(name: string): Promise { headers: { Origin: webURL, "Content-Type": "application/json" }, body: JSON.stringify({ email: `${name}@example.test`, password: "a long password", name, username: name }), }); + await twoFactorOn(db, name); return { cookie: res.headers.getSetCookie().map((c) => c.split(";")[0]).join("; "), name }; } diff --git a/apps/api/test/cases.test.ts b/apps/api/test/cases.test.ts index e471c23..a39b6ed 100644 --- a/apps/api/test/cases.test.ts +++ b/apps/api/test/cases.test.ts @@ -4,6 +4,7 @@ import { afterAll, beforeAll, expect, test } from "bun:test"; import { openDatabase, type Database } from "@t5de/db"; import { createApp } from "../src/app"; import { createAuth } from "../src/auth"; +import { twoFactorOn } from "./two-factor"; import { ImvuClient, type ImvuUser } from "../src/imvu"; const webURL = "http://web.test"; @@ -75,6 +76,7 @@ async function person(name: string): Promise { headers: { Origin: webURL, "Content-Type": "application/json" }, body: JSON.stringify({ email: `${name}@example.test`, password: "a long password", name, username: name }), }); + await twoFactorOn(db, name); return { cookie: res.headers.getSetCookie().map((c) => c.split(";")[0]).join("; "), name }; } diff --git a/apps/api/test/catalogs.test.ts b/apps/api/test/catalogs.test.ts index cf1920b..cca4738 100644 --- a/apps/api/test/catalogs.test.ts +++ b/apps/api/test/catalogs.test.ts @@ -4,6 +4,7 @@ import { afterAll, beforeAll, expect, test } from "bun:test"; import { openDatabase, type Database } from "@t5de/db"; import { createApp } from "../src/app"; import { createAuth } from "../src/auth"; +import { twoFactorOn } from "./two-factor"; import { ImvuClient, type ImvuUser } from "../src/imvu"; const webURL = "http://web.test"; @@ -75,6 +76,7 @@ async function person(name: string): Promise { headers: { Origin: webURL, "Content-Type": "application/json" }, body: JSON.stringify({ email: `${name}@example.test`, password: "a long password", name, username: name }), }); + await twoFactorOn(db, name); return { cookie: res.headers.getSetCookie().map((c) => c.split(";")[0]).join("; "), name }; } diff --git a/apps/api/test/hub.test.ts b/apps/api/test/hub.test.ts index cee6013..353c2c7 100644 --- a/apps/api/test/hub.test.ts +++ b/apps/api/test/hub.test.ts @@ -4,6 +4,7 @@ import { openDatabase, type Database } from "@t5de/db"; import { createApp } from "../src/app"; import { createAuth, proxyClientID } from "../src/auth"; import { ImvuClient, type ImvuUser } from "../src/imvu"; +import { twoFactorOn } from "./two-factor"; const webURL = "http://web.test"; const accounts = new Map(); @@ -239,6 +240,7 @@ describe("T5DE's proxy", () => { // A ban closes the connection and ends the proxy's session. const erinId = (await erin.call("GET", "/api/v1/me")).json.person.id; + await twoFactorOn(db, "alice"); const closed = new Promise((r) => (ws.onclose = r)); expect((await admin.call("POST", `/api/v1/console/people/${erinId}/ban`, { reason: "testing" })).status).toBe(200); await closed; diff --git a/apps/api/test/products.test.ts b/apps/api/test/products.test.ts index cbc5fc7..1771f88 100644 --- a/apps/api/test/products.test.ts +++ b/apps/api/test/products.test.ts @@ -4,6 +4,7 @@ import { createLocalJWKSet, jwtVerify } from "jose"; import { openDatabase, type Database } from "@t5de/db"; import { createApp } from "../src/app"; import { createAuth } from "../src/auth"; +import { twoFactorOn } from "./two-factor"; import { ImvuClient, imvuImage, parse, parseProduct, type ImvuUser } from "../src/imvu"; const webURL = "http://web.test"; @@ -82,6 +83,7 @@ async function person(name: string, imvu?: { id: number; ageVerified: boolean }) accounts.get(imvu.id)!.tagline = started.json.challenge.code; expect((await call(p, "POST", `/api/v1/account/links/${imvu.id}/check`)).status).toBe(200); } + await twoFactorOn(db, name); return p; } diff --git a/apps/api/test/registration.test.ts b/apps/api/test/registration.test.ts index 3af832f..8a17796 100644 --- a/apps/api/test/registration.test.ts +++ b/apps/api/test/registration.test.ts @@ -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); diff --git a/apps/api/test/tokens.test.ts b/apps/api/test/tokens.test.ts index 15a25e7..30d452a 100644 --- a/apps/api/test/tokens.test.ts +++ b/apps/api/test/tokens.test.ts @@ -4,6 +4,7 @@ import { afterAll, beforeAll, expect, test } from "bun:test"; import { eq, openDatabase, schema, type Database } from "@t5de/db"; import { createApp } from "../src/app"; import { createAuth } from "../src/auth"; +import { twoFactorOn } from "./two-factor"; import { ImvuClient, type ImvuUser } from "../src/imvu"; const webURL = "http://web.test"; @@ -75,6 +76,7 @@ async function person(name: string): Promise { headers: { Origin: webURL, "Content-Type": "application/json" }, body: JSON.stringify({ email: `${name}@example.test`, password: "a long password", name, username: name }), }); + await twoFactorOn(db, name); return { cookie: res.headers.getSetCookie().map((c) => c.split(";")[0]).join("; "), name }; } diff --git a/apps/api/test/two-factor.test.ts b/apps/api/test/two-factor.test.ts new file mode 100644 index 0000000..016ba5d --- /dev/null +++ b/apps/api/test/two-factor.test.ts @@ -0,0 +1,132 @@ +// Two-factor sign-in (docs/console.md): turning it on with an authenticator app, signing in with a code or a backup +// code, and sensitive permissions needing it. +import { afterAll, beforeAll, expect, test } from "bun:test"; +import { createHmac } from "node:crypto"; +import { openDatabase, type Database } from "@t5de/db"; +import { createApp } from "../src/app"; +import { createAuth } from "../src/auth"; +import { ImvuClient } from "../src/imvu"; + +const webURL = "http://web.test"; +const fakeIMVU = (async () => Response.json({ denormalized: {} })) as unknown as typeof fetch; + +let db: Database; +let close: () => Promise; +let base: string; +let stop: () => void; + +beforeAll(async () => { + ({ db, close } = await openDatabase("memory")); + const auth = createAuth(db, { apiURL: "http://api.test", webURL, secret: "test-secret-test-secret-test-secret-1234", rateLimit: false }); + const hub = createApp({ db, auth, imvu: new ImvuClient("http://imvu.test", fakeIMVU), webURL }); + hub.app.listen({ port: 0, hostname: "127.0.0.1" }); + const server = hub.app.server as unknown as { port: number; stop: () => void }; + stop = () => server.stop(); + base = `http://127.0.0.1:${server.port}`; +}); + +afterAll(async () => { + stop(); + await close(); +}); + +/** A browser: keeps its cookies (sign-in replaces them). */ +class Browser { + cookies = new Map(); + async call(method: string, path: string, body?: unknown) { + const res = await fetch(base + path, { + method, + headers: { + Origin: webURL, + ...(body !== undefined ? { "Content-Type": "application/json" } : {}), + Cookie: [...this.cookies].map(([k, v]) => `${k}=${v}`).join("; "), + }, + body: body !== undefined ? JSON.stringify(body) : undefined, + }); + for (const c of res.headers.getSetCookie()) { + const [pair, ...attrs] = c.split(";"); + const [k, v] = [pair!.slice(0, pair!.indexOf("=")), pair!.slice(pair!.indexOf("=") + 1)]; + if (!v || attrs.some((a) => /max-age=0\b/i.test(a.trim()))) this.cookies.delete(k); + else this.cookies.set(k, v); + } + const text = await res.text(); + return { status: res.status, json: text ? JSON.parse(text) : undefined }; + } +} + +/** The current code for an otpauth:// URI's secret (RFC 6238: SHA-1, 6 digits, 30 seconds). */ +function totp(uri: string): string { + const secret = new URL(uri).searchParams.get("secret")!; + const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; + let bits = ""; + for (const ch of secret.replace(/=+$/, "").toUpperCase()) bits += alphabet.indexOf(ch).toString(2).padStart(5, "0"); + const key = Buffer.from(bits.match(/.{8}/g)!.map((b) => parseInt(b, 2))); + const counter = Buffer.alloc(8); + counter.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000 / 30))); + const h = createHmac("sha1", key).update(counter).digest(); + const o = h[h.length - 1]! & 0xf; + return ((h.readUInt32BE(o) & 0x7fffffff) % 1_000_000).toString().padStart(6, "0"); +} + +const password = "a long password"; + +test("sensitive permissions need two-factor sign-in; turning it on, signing in with a code or a backup code", async () => { + const admin = new Browser(); + expect((await admin.call("POST", "/api/auth/sign-up/email", { email: "root@example.test", password, name: "root", username: "root" })).status).toBe(200); + const other = new Browser(); + await other.call("POST", "/api/auth/sign-up/email", { email: "pat@example.test", password, name: "pat", username: "pat" }); + const patId = (await other.call("GET", "/api/v1/me")).json.person.id; + + // Off: the account and the console say what needs it, and sensitive actions refuse. + const before = (await admin.call("GET", "/api/v1/account")).json; + expect(before.twoFactor.enabled).toBe(false); + expect(before.twoFactor.neededFor).toContain("person:ban"); + expect(before.twoFactor.neededFor).toContain("settings:edit"); + expect((await admin.call("GET", "/api/v1/console")).json.twoFactorNeededFor).toContain("person:role"); + const refused = await admin.call("POST", `/api/v1/console/people/${patId}/ban`, { reason: "testing" }); + expect(refused.status).toBe(403); + expect(refused.json).toMatchObject({ error: "two_factor_required", permission: "person:ban" }); + // People with nothing sensitive aren't asked. + expect((await other.call("GET", "/api/v1/account")).json.twoFactor).toEqual({ enabled: false, neededFor: [] }); + + // Better Auth's own admin endpoints are closed: they'd skip the check and the audit log. + expect((await admin.call("GET", "/api/auth/admin/list-users")).status).toBe(404); + expect((await admin.call("POST", "/api/auth/admin/ban-user", { userId: patId })).status).toBe(404); + + // Turning it on takes the password, then a code from the app. + expect((await admin.call("POST", "/api/auth/two-factor/enable", { password: "wrong password!" })).status).toBe(400); + const setup = (await admin.call("POST", "/api/auth/two-factor/enable", { password })).json; + expect(setup.totpURI).toStartWith("otpauth://totp/T5DE:"); + expect(setup.backupCodes).toHaveLength(10); + expect((await admin.call("GET", "/api/v1/account")).json.twoFactor.enabled).toBe(false); + expect((await admin.call("POST", "/api/auth/two-factor/verify-totp", { code: "000000" === totp(setup.totpURI) ? "111111" : "000000" })).status).toBe(401); + expect((await admin.call("POST", "/api/auth/two-factor/verify-totp", { code: totp(setup.totpURI) })).status).toBe(200); + const after = (await admin.call("GET", "/api/v1/account")).json; + expect(after.twoFactor.enabled).toBe(true); + expect(after.person.twoFactor).toBe(true); + expect((await admin.call("GET", "/api/v1/console")).json.twoFactorNeededFor).toEqual([]); + expect((await admin.call("POST", `/api/v1/console/people/${patId}/ban`, { reason: "testing" })).status).toBe(200); + + // Signing in now asks for a code: no session until it's given. + const again = new Browser(); + const first = await again.call("POST", "/api/auth/sign-in/username", { username: "root", password }); + expect(first.json).toMatchObject({ twoFactorRedirect: true, twoFactorMethods: ["totp"] }); + expect((await again.call("GET", "/api/v1/me")).status).toBe(401); + expect((await again.call("POST", "/api/auth/two-factor/verify-totp", { code: totp(setup.totpURI) })).status).toBe(200); + expect((await again.call("GET", "/api/v1/me")).json.person.username).toBe("root"); + + // A backup code works once. + const lost = new Browser(); + await lost.call("POST", "/api/auth/sign-in/username", { username: "root", password }); + expect((await lost.call("POST", "/api/auth/two-factor/verify-backup-code", { code: setup.backupCodes[0] })).status).toBe(200); + expect((await lost.call("GET", "/api/v1/me")).status).toBe(200); + const reused = new Browser(); + await reused.call("POST", "/api/auth/sign-in/username", { username: "root", password }); + expect((await reused.call("POST", "/api/auth/two-factor/verify-backup-code", { code: setup.backupCodes[0] })).status).not.toBe(200); + expect((await reused.call("GET", "/api/v1/me")).status).toBe(401); + + // Turning it off takes the password; sensitive actions refuse again. + expect((await admin.call("POST", "/api/auth/two-factor/disable", { password })).status).toBe(200); + expect((await admin.call("GET", "/api/v1/account")).json.twoFactor.enabled).toBe(false); + expect((await admin.call("POST", `/api/v1/console/people/${patId}/unban`)).json.error).toBe("two_factor_required"); +}); diff --git a/apps/api/test/two-factor.ts b/apps/api/test/two-factor.ts new file mode 100644 index 0000000..0c51230 --- /dev/null +++ b/apps/api/test/two-factor.ts @@ -0,0 +1,7 @@ +// 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())); diff --git a/apps/web/app/account/page.tsx b/apps/web/app/account/page.tsx index 419c274..71d798c 100644 --- a/apps/web/app/account/page.tsx +++ b/apps/web/app/account/page.tsx @@ -12,6 +12,7 @@ import { AgeCard } from "./age-card"; import { ChallengeCard } from "./challenge-card"; import { LinkCard } from "./link-card"; import { TokensCard } from "./tokens-card"; +import { TwoFactorCard } from "./two-factor-card"; export const metadata: Metadata = { title: "Account" }; @@ -122,6 +123,8 @@ export default async function Account({ searchParams }: { searchParams: Promise< + + ); diff --git a/apps/web/app/account/two-factor-card.tsx b/apps/web/app/account/two-factor-card.tsx new file mode 100644 index 0000000..8102700 --- /dev/null +++ b/apps/web/app/account/two-factor-card.tsx @@ -0,0 +1,291 @@ +"use client"; +// Two-factor sign-in on the account page: turning it on (scan a code into an authenticator app, keep the backup codes, +// confirm with a code), new backup codes, and turning it off. Sensitive permissions need it on. +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { renderSVG } from "uqr"; +import { CopyButton } from "@/components/copy-button"; +import { ErrorText } from "@/components/forms"; +import { Tag } from "@/components/status"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { authClient } from "@/lib/auth-client"; + +type Stage = + | { kind: "idle" } + | { kind: "password"; then: "enable" | "codes" | "disable" } + | { kind: "setup"; uri: string; codes: string[] } + | { kind: "codes"; codes: string[] }; + +export function TwoFactorCard({ + enabled, + neededFor, +}: { + enabled: boolean; + neededFor: string[]; +}) { + const router = useRouter(); + const [stage, setStage] = useState({ kind: "idle" }); + const [error, setError] = useState(""); + const [pending, setPending] = useState(false); + + async function run(fn: () => Promise) { + setError(""); + setPending(true); + const failed = await fn(); + if (failed) setError(failed); + setPending(false); + } + + async function withPassword( + then: "enable" | "codes" | "disable", + password: string, + ) { + if (then === "enable") { + const { data, error } = await authClient.twoFactor.enable({ password }); + if (error || !data || !("totpURI" in data) || !data.totpURI) + return error?.message ?? "That didn't work. Try again."; + setStage({ + kind: "setup", + uri: data.totpURI, + codes: data.backupCodes ?? [], + }); + } else if (then === "codes") { + const { data, error } = await authClient.twoFactor.generateBackupCodes({ + password, + }); + if (error || !data) + return error?.message ?? "That didn't work. Try again."; + setStage({ kind: "codes", codes: data.backupCodes }); + } else { + const { error } = await authClient.twoFactor.disable({ password }); + if (error) return error.message ?? "That didn't work. Try again."; + setStage({ kind: "idle" }); + router.refresh(); + } + } + + async function confirm(code: string) { + const { error } = await authClient.twoFactor.verifyTotp({ + code: code.replace(/\s+/g, ""), + }); + if (error) return error.message ?? "That code didn't work. Try again."; + setStage({ kind: "idle" }); + router.refresh(); + } + + const submitTo = + (fn: (form: FormData) => Promise) => + (e: React.FormEvent) => { + e.preventDefault(); + const form = new FormData(e.currentTarget); + void run(() => fn(form)); + }; + + return ( + + + + Two-Factor Sign-In {enabled && on} + + + Signing in asks for a code from an authenticator app on your phone as + well as your password. + + + + {!enabled && neededFor.length > 0 && stage.kind !== "setup" && ( + + Turn this on to use everything you can do + + + These need it:{" "} + {neededFor.map((p, i) => ( + + {i > 0 && ", "} + {p} + + ))} + . + + + + )} + + {stage.kind === "idle" && + (enabled ? ( +
+ + +
+ ) : ( + + ))} + + {stage.kind === "password" && ( +
+ withPassword(stage.then, String(f.get("password"))), + )} + className="space-y-3" + > +

+ {stage.then === "disable" + ? neededFor.length > 0 + ? "Turning it off stops the things listed above working until you turn it on again. Enter your password." + : "Enter your password to turn it off." + : stage.then === "codes" + ? "Your old backup codes stop working. Enter your password." + : "Enter your password to start."} +

+
+ + + +
+
+ )} + + {stage.kind === "setup" && ( +
+
    +
  1. +

    + Scan this with an authenticator app (such as Google + Authenticator, Microsoft Authenticator or 1Password). +

    +
    +

    + Or enter this key:{" "} + + {new URL(stage.uri).searchParams.get("secret")} + +

    +
  2. +
  3. +

    + Keep these backup codes somewhere safe. Each signs you in once + if you lose your phone. +

    + +
  4. +
  5. +

    Enter the code the app shows.

    +
    confirm(String(f.get("code"))))} + className="flex max-w-md flex-wrap gap-2" + > + + + +
    +
  6. +
+
+ )} + + {stage.kind === "codes" && ( +
+

+ Your new backup codes. Keep them somewhere safe: they won't + be shown again. +

+ + +
+ )} + + {error && {error}} +
+
+ ); +} + +function BackupCodes({ codes }: { codes: string[] }) { + return ( +
+
    + {codes.map((c) => ( +
  • {c}
  • + ))} +
+ +
+ ); +} diff --git a/apps/web/app/console/console-nav.tsx b/apps/web/app/console/console-nav.tsx index 14f4517..4ee46f2 100644 --- a/apps/web/app/console/console-nav.tsx +++ b/apps/web/app/console/console-nav.tsx @@ -1,7 +1,16 @@ +import Link from "next/link"; import { notFound, redirect } from "next/navigation"; import { cache } from "react"; import { NavLink } from "@/components/header-client"; -import { api, getMe, isModerator, unwrap, type ConsoleData, type Person } from "@/lib/api"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; +import { + api, + getMe, + isModerator, + unwrap, + type ConsoleData, + type Person, +} from "@/lib/api"; /** The signed-in moderator, or off to sign in; others get not found (these pages aren't for them). */ export async function requireModerator(path: string): Promise { @@ -22,7 +31,9 @@ const loadConsole = cache(async (): Promise => { * The signed-in person and their console, or off to sign in. People who manage nothing get not found: the console * is for those controlling a product, catalog or room. */ -export async function requireConsole(path: string): Promise<{ me: Person; console: ConsoleData }> { +export async function requireConsole( + path: string, +): Promise<{ me: Person; console: ConsoleData }> { const me = await getMe(); if (!me) redirect(`/signin?next=${encodeURIComponent(path)}`); const data = await loadConsole(); @@ -43,18 +54,43 @@ const tabs: { section: Section; href: string; label: string }[] = [ { section: "audit", href: "/console/audit", label: "Audit" }, ]; -/** The console's sections this person may see. */ +/** The console's sections this person may see, and a reminder when sensitive actions need two-factor sign-in. */ export async function ConsoleNav() { - const sections = new Set
((await loadConsole())?.sections ?? ["overview"]); + const data = await loadConsole(); + const sections = new Set
(data?.sections ?? ["overview"]); + const needed = data?.twoFactorNeededFor ?? []; return ( - + <> + {needed.length > 0 && ( + + Turn on two-factor sign-in + + + Some of what you can do here needs it ({needed.join(", ")}).{" "} + + Turn it on in your account + + . + + + + )} + + ); } diff --git a/apps/web/app/console/people/[id]/page.tsx b/apps/web/app/console/people/[id]/page.tsx index db3c448..6969aaa 100644 --- a/apps/web/app/console/people/[id]/page.tsx +++ b/apps/web/app/console/people/[id]/page.tsx @@ -36,6 +36,7 @@ export default async function PersonPage({ params }: { params: Promise<{ id: str {person.banned && banned: {person.banReason}} {!person.approved && waiting for approval} + {person.twoFactor && two-factor on} diff --git a/apps/web/app/console/people/page.tsx b/apps/web/app/console/people/page.tsx index 11f2ad5..a1864dd 100644 --- a/apps/web/app/console/people/page.tsx +++ b/apps/web/app/console/people/page.tsx @@ -65,7 +65,12 @@ export default async function People({ {p.username} - {p.role} + + {p.role} + {p.role !== "user" && !p.twoFactor && ( + no two-factor + )} + {p.linkCap} diff --git a/apps/web/app/signin/signin-form.tsx b/apps/web/app/signin/signin-form.tsx index 5d60b86..a4653ed 100644 --- a/apps/web/app/signin/signin-form.tsx +++ b/apps/web/app/signin/signin-form.tsx @@ -4,30 +4,56 @@ import { useRouter } from "next/navigation"; import { useState } from "react"; import { ErrorText } from "@/components/forms"; import { Button } from "@/components/ui/button"; -import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field"; +import { + Field, + FieldDescription, + FieldGroup, + FieldLabel, +} from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { authClient } from "@/lib/auth-client"; -/** Signs in with Better Auth, then goes to next (already checked to be a path on this site). */ +/** Signs in with Better Auth (then a code, if two-factor sign-in is on), then goes to next (already checked to be a + * path on this site). */ export function SignInForm({ next }: { next: string }) { const router = useRouter(); const [error, setError] = useState(""); const [pending, setPending] = useState(false); + // After the password, when two-factor sign-in is on: a code from the app, or a backup code. + const [step, setStep] = useState<"password" | "code" | "backup">("password"); + + const done = () => { + router.push(next); + router.refresh(); + }; + + async function signIn(form: FormData) { + const { data, error } = await authClient.signIn.username({ + username: String(form.get("username")), + password: String(form.get("password")), + }); + if (error) return setError(error.message ?? "That didn't work. Try again."); + if (data && "twoFactorRedirect" in data && data.twoFactorRedirect) + return setStep("code"); + done(); + } + + async function verify(form: FormData) { + const code = String(form.get("code")).replace(/\s+/g, ""); + const { error } = + step === "code" + ? await authClient.twoFactor.verifyTotp({ code }) + : await authClient.twoFactor.verifyBackupCode({ code }); + if (error) + return setError(error.message ?? "That code didn't work. Try again."); + done(); + } async function submit(form: FormData) { setError(""); setPending(true); - const { error } = await authClient.signIn.username({ - username: String(form.get("username")), - password: String(form.get("password")), - }); - if (error) { - setError(error.message ?? "That didn't work. Try again."); - setPending(false); - return; - } - router.push(next); - router.refresh(); + await (step === "password" ? signIn(form) : verify(form)); + setPending(false); } return ( @@ -37,25 +63,84 @@ export function SignInForm({ next }: { next: string }) { void submit(new FormData(e.currentTarget)); }} > - - - Username - - - - Password - - - {error && {error}} - - - - No account? Create one - - - + {step === "password" ? ( + + + Username + + + + Password + + + {error && {error}} + + + + No account? Create one + + + + ) : ( + + + + {step === "code" + ? "Code from your authenticator app" + : "Backup code"} + + + + {error && {error}} + + + + + + + + )} ); } diff --git a/apps/web/lib/auth-client.ts b/apps/web/lib/auth-client.ts index 61b6258..d29456e 100644 --- a/apps/web/lib/auth-client.ts +++ b/apps/web/lib/auth-client.ts @@ -1,10 +1,10 @@ -// Better Auth in the browser: sign-up, sign-in and sign-out. Its requests go to /api/auth on this site, which Next -// rewrites to the API, so the session cookie is set for this site. +// Better Auth in the browser: sign-up, sign-in (with a two-factor code when it's on), sign-out, and two-factor setup. +// Its requests go to /api/auth on this site, which Next rewrites to the API, so the session cookie is set for this site. "use client"; import { createAuthClient } from "better-auth/react"; -import { usernameClient } from "better-auth/client/plugins"; +import { twoFactorClient, usernameClient } from "better-auth/client/plugins"; export const authClient = createAuthClient({ baseURL: typeof window === "undefined" ? undefined : window.location.origin, - plugins: [usernameClient()], + plugins: [usernameClient(), twoFactorClient()], }); diff --git a/apps/web/package.json b/apps/web/package.json index 36846fd..f0c1912 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -19,7 +19,8 @@ "next": "16.4.3", "react": "19.3.1", "react-dom": "19.3.1", - "server-only": "^0.0.1" + "server-only": "^0.0.1", + "uqr": "^0.1.3" }, "devDependencies": { "@tailwindcss/postcss": "^4.3.3", diff --git a/bun.lock b/bun.lock index 9bae489..4d19c4a 100644 --- a/bun.lock +++ b/bun.lock @@ -14,8 +14,8 @@ "@t5de/db": "workspace:*", "better-auth": "1.7.14", "elysia": "1.4.30", - "jose": "^6.2.14", - "sanitize-html": "^2.18.1", + "jose": "6.2.14", + "sanitize-html": "2.18.1", }, "devDependencies": { "@types/bun": "^1.4.4", @@ -37,6 +37,7 @@ "react": "19.3.1", "react-dom": "19.3.1", "server-only": "^0.0.1", + "uqr": "^0.1.3", }, "devDependencies": { "@tailwindcss/postcss": "^4.3.3", @@ -884,6 +885,8 @@ "update-browserslist-db": ["update-browserslist-db@1.3.4", "", { "dependencies": { "escalade": "^3.2.0", "picocolors": "^1.1.1" }, "peerDependencies": { "browserslist": ">= 4.21.0" }, "bin": { "update-browserslist-db": "cli.js" } }, "sha512-t8wonIOdQyOjtPd2VktlBu6QjTVTks6v8bSi7kd0r2Vll8TK1JYDZtRRdbmCHOAMphkZgrzK+L+vXK4pyZ8t4A=="], + "uqr": ["uqr@0.1.3", "", {}, "sha512-0rjE8iEJe4YmT9TOhwsZtqCMRLc5DXZUI2UEYUUg63ikBkqqE5EYWaI0etFe/5KUcmcYwLih2RND1kq+hrUJXA=="], + "use-sync-external-store": ["use-sync-external-store@1.7.0", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-6L+EeigHMQhdaIPNIFUKwfWJSwWFQ8gJbJ2DLOs5sDIegTwR9fRxvnM3uciHKjIZhFz+KAv2emhWMRvDmMcY8A=="], "util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="], diff --git a/docs/api.md b/docs/api.md index b2b63cd..c4b3767 100644 --- a/docs/api.md +++ b/docs/api.md @@ -20,7 +20,8 @@ is. Codes: `invalid`, `signed_out`, `forbidden`, `not_found`, `no_such_imvu_acco | | | | --- | --- | | `POST /api/auth/sign-up/email` | `{email, password, name, username}`. Usernames 3-32 of `A-Za-z0-9_`; passwords 10-256 characters. The first account is an admin. With registration closed, the others wait for approval (`approved: false`): every route but `/me` answers 403 `awaiting_approval`, and the rest of the hub treats them as signed out. | -| `POST /api/auth/sign-in/username` | `{username, password}` | +| `POST /api/auth/sign-in/username` | `{username, password}`. With two-factor sign-in on, it answers `{twoFactorRedirect: true, twoFactorMethods: ["totp"]}` and no session: then `POST /api/auth/two-factor/verify-totp` `{code}` (from the app) or `/verify-backup-code` `{code}` signs in. | +| `POST /api/auth/two-factor/enable` | `{password}` → `{totpURI, backupCodes}`; on once `POST /api/auth/two-factor/verify-totp` `{code}` confirms it. `/two-factor/disable` and `/two-factor/generate-backup-codes` take `{password}`. Sensitive permissions need it on (docs/console.md). `/api/auth/admin/*` answers 404. | | `POST /api/auth/sign-out` | | | `GET /api/v1/me` | `{person}` (`approved` false while waiting), with `picture`: the avatar picture of their first linked IMVU account (from IMVU, kept an hour), or `null`, `console`: whether the console is for them, and `unread`: their unread notifications | | `GET /api/v1/hub` | (anyone) `{registration}`: `open` or `closed` | diff --git a/docs/console.md b/docs/console.md index 674cc67..c8fd091 100644 --- a/docs/console.md +++ b/docs/console.md @@ -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 diff --git a/docs/design.md b/docs/design.md index a889a38..a54ffc8 100644 --- a/docs/design.md +++ b/docs/design.md @@ -478,8 +478,8 @@ Phases for products, catalogs and imports (products.md, console.md, imports.md): (to look into with the importer spike). 3. Cases (reports, appeals, reviews), file blocks and the catalogs' changes feed; notifications; API tokens; two-factor sign-in for sensitive permissions. Cases and notifications **done** (2026-11-05), without email, canned - reasons, moderator notes or second approval. File blocks and API tokens **done** (2026-11-05); two-factor - sign-in next. + reasons, moderator notes or second approval. File blocks, API tokens and two-factor sign-in **done** + (2026-11-05); auditing turning two-factor on and off, and "trust this browser", later. 4. Imports: grants, recorded grants, requests, unclaimed creators, the job queue, `t5de-importer` (after its spike). 5. Charts and stats; mirroring between catalogs. diff --git a/packages/db/drizzle/0015_two_factor.sql b/packages/db/drizzle/0015_two_factor.sql new file mode 100644 index 0000000..416fd33 --- /dev/null +++ b/packages/db/drizzle/0015_two_factor.sql @@ -0,0 +1,14 @@ +CREATE TABLE "two_factor" ( + "id" text PRIMARY KEY NOT NULL, + "user_id" text NOT NULL, + "secret" text NOT NULL, + "backup_codes" text NOT NULL, + "verified" boolean DEFAULT true NOT NULL, + "failed_verification_count" integer DEFAULT 0 NOT NULL, + "locked_until" timestamp with time zone +); +--> statement-breakpoint +ALTER TABLE "user" ADD COLUMN "two_factor_enabled" boolean DEFAULT false NOT NULL;--> statement-breakpoint +ALTER TABLE "two_factor" ADD CONSTRAINT "two_factor_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "two_factor_user" ON "two_factor" USING btree ("user_id");--> statement-breakpoint +CREATE INDEX "two_factor_secret" ON "two_factor" USING btree ("secret"); \ No newline at end of file diff --git a/packages/db/drizzle/meta/0015_snapshot.json b/packages/db/drizzle/meta/0015_snapshot.json new file mode 100644 index 0000000..d177ea0 --- /dev/null +++ b/packages/db/drizzle/meta/0015_snapshot.json @@ -0,0 +1,3609 @@ +{ + "id": "089adb14-f6f8-46cf-9a87-daf4b32c9499", + "prevId": "d9f8b65a-98c7-457f-afe7-bc8d097a3741", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "account_user": { + "name": "account_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.age_check": { + "name": "age_check", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "over_eighteen": { + "name": "over_eighteen", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "provider_ref": { + "name": "provider_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "age_check_user": { + "name": "age_check_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "age_check_imvu": { + "name": "age_check_imvu", + "columns": [ + { + "expression": "imvu_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "age_check_provider_ref": { + "name": "age_check_provider_ref", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "age_check_user_id_user_id_fk": { + "name": "age_check_user_id_user_id_fk", + "tableFrom": "age_check", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.api_token": { + "name": "api_token", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "hash": { + "name": "hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "grants": { + "name": "grants", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "api_token_hash": { + "name": "api_token_hash", + "columns": [ + { + "expression": "hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "api_token_user": { + "name": "api_token_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "api_token_user_id_user_id_fk": { + "name": "api_token_user_id_user_id_fk", + "tableFrom": "api_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit": { + "name": "audit", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "at": { + "name": "at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target": { + "name": "target", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "detail": { + "name": "detail", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + } + }, + "indexes": { + "audit_at": { + "name": "audit_at", + "columns": [ + { + "expression": "at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_tags": { + "name": "audit_tags", + "columns": [ + { + "expression": "tags", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "audit_actor_id_user_id_fk": { + "name": "audit_actor_id_user_id_fk", + "tableFrom": "audit", + "tableTo": "user", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.case_note": { + "name": "case_note", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "case_id": { + "name": "case_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "by_id": { + "name": "by_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "internal": { + "name": "internal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "case_note_case": { + "name": "case_note_case", + "columns": [ + { + "expression": "case_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "case_note_case_id_moderation_case_id_fk": { + "name": "case_note_case_id_moderation_case_id_fk", + "tableFrom": "case_note", + "tableTo": "moderation_case", + "columnsFrom": [ + "case_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "case_note_by_id_user_id_fk": { + "name": "case_note_by_id_user_id_fk", + "tableFrom": "case_note", + "tableTo": "user", + "columnsFrom": [ + "by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.catalog": { + "name": "catalog", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact": { + "name": "contact", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'public'" + }, + "membership": { + "name": "membership", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "status_reason": { + "name": "status_reason", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "max_rating": { + "name": "max_rating", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'adult'" + }, + "uploads": { + "name": "uploads", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'anyone'" + }, + "mirrors": { + "name": "mirrors", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'approve'" + }, + "key_hash": { + "name": "key_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_url": { + "name": "catalog_url", + "columns": [ + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_owner_id_user_id_fk": { + "name": "catalog_owner_id_user_id_fk", + "tableFrom": "catalog", + "tableTo": "user", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.catalog_change": { + "name": "catalog_change", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_change_catalog": { + "name": "catalog_change_catalog", + "columns": [ + { + "expression": "catalog_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_change_catalog_id_catalog_id_fk": { + "name": "catalog_change_catalog_id_catalog_id_fk", + "tableFrom": "catalog_change", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.catalog_invite": { + "name": "catalog_invite", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "max_uses": { + "name": "max_uses", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uses": { + "name": "uses", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_invite_catalog": { + "name": "catalog_invite_catalog", + "columns": [ + { + "expression": "catalog_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_invite_catalog_id_catalog_id_fk": { + "name": "catalog_invite_catalog_id_catalog_id_fk", + "tableFrom": "catalog_invite", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "catalog_invite_created_by_user_id_fk": { + "name": "catalog_invite_created_by_user_id_fk", + "tableFrom": "catalog_invite", + "tableTo": "user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.catalog_member": { + "name": "catalog_member", + "schema": "", + "columns": { + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invite": { + "name": "invite", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "decided_by": { + "name": "decided_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_member_user": { + "name": "catalog_member_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_member_catalog_id_catalog_id_fk": { + "name": "catalog_member_catalog_id_catalog_id_fk", + "tableFrom": "catalog_member", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "catalog_member_user_id_user_id_fk": { + "name": "catalog_member_user_id_user_id_fk", + "tableFrom": "catalog_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "catalog_member_decided_by_user_id_fk": { + "name": "catalog_member_decided_by_user_id_fk", + "tableFrom": "catalog_member", + "tableTo": "user", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "catalog_member_catalog_id_user_id_pk": { + "name": "catalog_member_catalog_id_user_id_pk", + "columns": [ + "catalog_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.device_code": { + "name": "device_code", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "device_code": { + "name": "device_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_code": { + "name": "user_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_polled_at": { + "name": "last_polled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "polling_interval": { + "name": "polling_interval", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "device_code_user_id_user_id_fk": { + "name": "device_code_user_id_user_id_fk", + "tableFrom": "device_code", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.file_block": { + "name": "file_block", + "schema": "", + "columns": { + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "by_id": { + "name": "by_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "file_block_by_id_user_id_fk": { + "name": "file_block_by_id_user_id_fk", + "tableFrom": "file_block", + "tableTo": "user", + "columnsFrom": [ + "by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room": { + "name": "hosted_room", + "schema": "", + "columns": { + "n": { + "name": "n", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "owner_imvu_id": { + "name": "owner_imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "room_pid": { + "name": "room_pid", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'general'" + }, + "max_users": { + "name": "max_users", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 10 + }, + "scene": { + "name": "scene", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "scene_hash": { + "name": "scene_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "closed": { + "name": "closed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "privacy": { + "name": "privacy", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'public'" + }, + "moderators": { + "name": "moderators", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "image_hash": { + "name": "image_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "hosted_room_owner": { + "name": "hosted_room_owner", + "columns": [ + { + "expression": "owner_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "hosted_room_created": { + "name": "hosted_room_created", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "hosted_room_owner_id_user_id_fk": { + "name": "hosted_room_owner_id_user_id_fk", + "tableFrom": "hosted_room", + "tableTo": "user", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_ban": { + "name": "hosted_room_ban", + "schema": "", + "columns": { + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "by_imvu_id": { + "name": "by_imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "until": { + "name": "until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "hosted_room_ban_n_hosted_room_n_fk": { + "name": "hosted_room_ban_n_hosted_room_n_fk", + "tableFrom": "hosted_room_ban", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosted_room_ban_n_imvu_id_pk": { + "name": "hosted_room_ban_n_imvu_id_pk", + "columns": [ + "n", + "imvu_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_favorite": { + "name": "hosted_room_favorite", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "hosted_room_favorite_user_id_user_id_fk": { + "name": "hosted_room_favorite_user_id_user_id_fk", + "tableFrom": "hosted_room_favorite", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "hosted_room_favorite_n_hosted_room_n_fk": { + "name": "hosted_room_favorite_n_hosted_room_n_fk", + "tableFrom": "hosted_room_favorite", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosted_room_favorite_user_id_n_pk": { + "name": "hosted_room_favorite_user_id_n_pk", + "columns": [ + "user_id", + "n" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_image": { + "name": "hosted_room_image", + "schema": "", + "columns": { + "n": { + "name": "n", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "hash": { + "name": "hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "hosted_room_image_n_hosted_room_n_fk": { + "name": "hosted_room_image_n_hosted_room_n_fk", + "tableFrom": "hosted_room_image", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_rating": { + "name": "hosted_room_rating", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "hosted_room_rating_room": { + "name": "hosted_room_rating_room", + "columns": [ + { + "expression": "n", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "hosted_room_rating_user_id_user_id_fk": { + "name": "hosted_room_rating_user_id_user_id_fk", + "tableFrom": "hosted_room_rating", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "hosted_room_rating_n_hosted_room_n_fk": { + "name": "hosted_room_rating_n_hosted_room_n_fk", + "tableFrom": "hosted_room_rating", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosted_room_rating_user_id_n_pk": { + "name": "hosted_room_rating_user_id_n_pk", + "columns": [ + "user_id", + "n" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_visit": { + "name": "hosted_room_visit", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "at": { + "name": "at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "hosted_room_visit_at": { + "name": "hosted_room_visit_at", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "hosted_room_visit_user_id_user_id_fk": { + "name": "hosted_room_visit_user_id_user_id_fk", + "tableFrom": "hosted_room_visit", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "hosted_room_visit_n_hosted_room_n_fk": { + "name": "hosted_room_visit_n_hosted_room_n_fk", + "tableFrom": "hosted_room_visit", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosted_room_visit_user_id_n_pk": { + "name": "hosted_room_visit_user_id_n_pk", + "columns": [ + "user_id", + "n" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosting": { + "name": "hosting", + "schema": "", + "columns": { + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "product_id": { + "name": "product_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "hosting_product": { + "name": "hosting_product", + "columns": [ + { + "expression": "product_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "hosting_catalog_id_catalog_id_fk": { + "name": "hosting_catalog_id_catalog_id_fk", + "tableFrom": "hosting", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosting_catalog_id_product_id_number_pk": { + "name": "hosting_catalog_id_product_id_number_pk", + "columns": [ + "catalog_id", + "product_id", + "number" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hub_setting": { + "name": "hub_setting", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.imvu_link": { + "name": "imvu_link", + "schema": "", + "columns": { + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pairwise_id": { + "name": "pairwise_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "linked_at": { + "name": "linked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "show_badge": { + "name": "show_badge", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "show_presence": { + "name": "show_presence", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "list_rooms": { + "name": "list_rooms", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "imvu_link_user": { + "name": "imvu_link_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "imvu_link_user_id_user_id_fk": { + "name": "imvu_link_user_id_user_id_fk", + "tableFrom": "imvu_link", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "imvu_link_pairwise_id_unique": { + "name": "imvu_link_pairwise_id_unique", + "nullsNotDistinct": false, + "columns": [ + "pairwise_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.jwks": { + "name": "jwks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "private_key": { + "name": "private_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "alg": { + "name": "alg", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "crv": { + "name": "crv", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.library": { + "name": "library", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "product_id": { + "name": "product_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "stay_on": { + "name": "stay_on", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "added_at": { + "name": "added_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "library_user_id_user_id_fk": { + "name": "library_user_id_user_id_fk", + "tableFrom": "library", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "library_product_id_product_id_fk": { + "name": "library_product_id_product_id_fk", + "tableFrom": "library", + "tableTo": "product", + "columnsFrom": [ + "product_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "library_user_id_product_id_pk": { + "name": "library_user_id_product_id_pk", + "columns": [ + "user_id", + "product_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.link_challenge": { + "name": "link_challenge", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "link_challenge_user_id_user_id_fk": { + "name": "link_challenge_user_id_user_id_fk", + "tableFrom": "link_challenge", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "link_challenge_user_id_imvu_id_pk": { + "name": "link_challenge_user_id_imvu_id_pk", + "columns": [ + "user_id", + "imvu_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.moderation_case": { + "name": "moderation_case", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "opened_by": { + "name": "opened_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assignee": { + "name": "assignee", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "resolution": { + "name": "resolution", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "decided_by": { + "name": "decided_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "moderation_case_status": { + "name": "moderation_case_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "moderation_case_opened_by": { + "name": "moderation_case_opened_by", + "columns": [ + { + "expression": "opened_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "moderation_case_tags": { + "name": "moderation_case_tags", + "columns": [ + { + "expression": "tags", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "moderation_case_opened_by_user_id_fk": { + "name": "moderation_case_opened_by_user_id_fk", + "tableFrom": "moderation_case", + "tableTo": "user", + "columnsFrom": [ + "opened_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "moderation_case_assignee_user_id_fk": { + "name": "moderation_case_assignee_user_id_fk", + "tableFrom": "moderation_case", + "tableTo": "user", + "columnsFrom": [ + "assignee" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "moderation_case_decided_by_user_id_fk": { + "name": "moderation_case_decided_by_user_id_fk", + "tableFrom": "moderation_case", + "tableTo": "user", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notification": { + "name": "notification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "notification_user": { + "name": "notification_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "notification_user_id_user_id_fk": { + "name": "notification_user_id_user_id_fk", + "tableFrom": "notification", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.product": { + "name": "product", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "creator_id": { + "name": "creator_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "rating": { + "name": "rating", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "latest": { + "name": "latest", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'published'" + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "listed": { + "name": "listed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "category": { + "name": "category", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "locked": { + "name": "locked", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "removed_at": { + "name": "removed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "removed_reason": { + "name": "removed_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "product_creator": { + "name": "product_creator", + "columns": [ + { + "expression": "creator_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "product_created": { + "name": "product_created", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "product_tags": { + "name": "product_tags", + "columns": [ + { + "expression": "tags", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "product_creator_id_user_id_fk": { + "name": "product_creator_id_user_id_fk", + "tableFrom": "product", + "tableTo": "user", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.product_info_change": { + "name": "product_info_change", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "product_id": { + "name": "product_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "by_id": { + "name": "by_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "changes": { + "name": "changes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "revert_of": { + "name": "revert_of", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "product_info_change_product": { + "name": "product_info_change_product", + "columns": [ + { + "expression": "product_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "product_info_change_product_id_product_id_fk": { + "name": "product_info_change_product_id_product_id_fk", + "tableFrom": "product_info_change", + "tableTo": "product", + "columnsFrom": [ + "product_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "product_info_change_by_id_user_id_fk": { + "name": "product_info_change_by_id_user_id_fk", + "tableFrom": "product_info_change", + "tableTo": "user", + "columnsFrom": [ + "by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.product_revision": { + "name": "product_revision", + "schema": "", + "columns": { + "product_id": { + "name": "product_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "files": { + "name": "files", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent": { + "name": "parent", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "parent_info": { + "name": "parent_info", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retracted": { + "name": "retracted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "product_revision_files": { + "name": "product_revision_files", + "columns": [ + { + "expression": "files", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "product_revision_product_id_product_id_fk": { + "name": "product_revision_product_id_product_id_fk", + "tableFrom": "product_revision", + "tableTo": "product", + "columnsFrom": [ + "product_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "product_revision_uploaded_by_user_id_fk": { + "name": "product_revision_uploaded_by_user_id_fk", + "tableFrom": "product_revision", + "tableTo": "user", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "product_revision_product_id_number_pk": { + "name": "product_revision_product_id_number_pk", + "columns": [ + "product_id", + "number" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.role_assignment": { + "name": "role_assignment", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scope_type": { + "name": "scope_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scope_id": { + "name": "scope_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "granted_by": { + "name": "granted_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "role_assignment_scope": { + "name": "role_assignment_scope", + "columns": [ + { + "expression": "scope_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scope_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "role_assignment_user_id_user_id_fk": { + "name": "role_assignment_user_id_user_id_fk", + "tableFrom": "role_assignment", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "role_assignment_granted_by_user_id_fk": { + "name": "role_assignment_granted_by_user_id_fk", + "tableFrom": "role_assignment", + "tableTo": "user", + "columnsFrom": [ + "granted_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "role_assignment_user_id_role_scope_type_scope_id_pk": { + "name": "role_assignment_user_id_role_scope_type_scope_id_pk", + "columns": [ + "user_id", + "role", + "scope_type", + "scope_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.room": { + "name": "room", + "schema": "", + "columns": { + "instance_id": { + "name": "instance_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "owner_imvu_id": { + "name": "owner_imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "image_url": { + "name": "image_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "privacy": { + "name": "privacy", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_rating": { + "name": "content_rating", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "access_pass": { + "name": "access_pass", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "occupancy": { + "name": "occupancy", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "capacity": { + "name": "capacity", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "expired": { + "name": "expired", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "seen_at": { + "name": "seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "room_owner": { + "name": "room_owner", + "columns": [ + { + "expression": "owner_imvu_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.room_decoration": { + "name": "room_decoration", + "schema": "", + "columns": { + "instance_id": { + "name": "instance_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "owner_imvu_id": { + "name": "owner_imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "contents": { + "name": "contents", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "room_decoration_owner": { + "name": "room_decoration_owner", + "columns": [ + { + "expression": "owner_imvu_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "impersonated_by": { + "name": "impersonated_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "session_user": { + "name": "session_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.signing_key": { + "name": "signing_key", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "private_key": { + "name": "private_key", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.two_factor": { + "name": "two_factor", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "backup_codes": { + "name": "backup_codes", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "failed_verification_count": { + "name": "failed_verification_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "two_factor_user": { + "name": "two_factor_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "two_factor_secret": { + "name": "two_factor_secret", + "columns": [ + { + "expression": "secret", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "two_factor_user_id_user_id_fk": { + "name": "two_factor_user_id_user_id_fk", + "tableFrom": "two_factor", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "display_username": { + "name": "display_username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'user'" + }, + "banned": { + "name": "banned", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "ban_reason": { + "name": "ban_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ban_expires": { + "name": "ban_expires", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "link_cap": { + "name": "link_cap", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 10 + }, + "approved": { + "name": "approved", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "two_factor_enabled": { + "name": "two_factor_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "user_username_lower": { + "name": "user_username_lower", + "columns": [ + { + "expression": "lower(\"username\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "user_username_unique": { + "name": "user_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "verification_identifier": { + "name": "verification_identifier", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.json index 6d1300a..51fc7d9 100644 --- a/packages/db/drizzle/meta/_journal.json +++ b/packages/db/drizzle/meta/_journal.json @@ -106,6 +106,13 @@ "when": 1793918993367, "tag": "0014_api_tokens", "breakpoints": true + }, + { + "idx": 15, + "version": "7", + "when": 1793934143730, + "tag": "0015_two_factor", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index 2cba421..820cf66 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -45,6 +45,8 @@ export const user = pgTable( linkCap: integer("link_cap").notNull().default(10), // False while a new account waits for a moderator's approval (registration closed); it can only sign in. approved: boolean("approved").notNull().default(true), + // Two-factor sign-in (an authenticator app), required for sensitive permissions (docs/console.md). + twoFactorEnabled: boolean("two_factor_enabled").notNull().default(false), }, (t) => [uniqueIndex("user_username_lower").on(sql`lower(${t.username})`)], ); @@ -112,6 +114,23 @@ export const jwks = pgTable("jwks", { crv: text("crv"), }); +// Two-factor sign-in: the person's authenticator secret and backup codes (both encrypted by Better Auth). +export const twoFactor = pgTable( + "two_factor", + { + id: text("id").primaryKey(), + userId: text("user_id") + .notNull() + .references(() => user.id, { onDelete: "cascade" }), + secret: text("secret").notNull(), + backupCodes: text("backup_codes").notNull(), + verified: boolean("verified").notNull().default(true), + failedVerificationCount: integer("failed_verification_count").notNull().default(0), + lockedUntil: timestamp("locked_until", { withTimezone: true }), + }, + (t) => [index("two_factor_user").on(t.userId), index("two_factor_secret").on(t.secret)], +); + // A T5DE proxy signing in: it shows userCode, the person approves it on the website. export const deviceCode = pgTable("device_code", { id: text("id").primaryKey(),