SPB Git

Repository Public

setup-token.ts 1.4 KB 25 lines typescript

1import "./_env";2import { sql } from "../src/lib/db";3import { env } from "../src/lib/env";4import { issueSetupToken } from "../src/lib/auth";56/**7 * Recovery from the server's shell (the only recovery path besides the printed recovery codes).8 *   tsx scripts/setup-token.ts                      → owner: add a passkey (existing ones kept)9 *   tsx scripts/setup-token.ts --recovery           → owner: replace every passkey, sign out every device10 *   tsx scripts/setup-token.ts --user a@b.c [...]   → same for another account11 * The link is printed on the terminal only; run it interactively, never from a job whose output is logged.12 */13async function main() {14  const recovery = process.argv.includes("--recovery");15  const i = process.argv.indexOf("--user");16  const email = i > 0 ? process.argv[i + 1] : null;17  const [u] = email ? await sql<{ id: string }[]>`SELECT id FROM users WHERE email = ${email}` : await sql<{ id: string }[]>`SELECT id FROM users WHERE is_owner`;18  if (!u) throw new Error(email ? `No account ${email}` : "No owner account: run scripts/bootstrap.ts first");19  const token = await issueSetupToken(u.id, recovery ? "recovery" : "setup", 30);20  console.log(`${env.appUrl}/setup#${token}`);21  console.log(recovery ? "Valid 30 minutes, one use. Enrolling with it REMOVES the other passkeys and signs out every device." : "Valid 30 minutes, one use.");22  await sql.end();23}24main().catch((e) => { console.error(e.message); process.exit(1); });25
Files main
Menu

Theme