Files
CatoandClaude 0b8e9246c6 feat(auth): every way in on AccountKit's own screens (#160)
Vita answers sign-in from AccountKit since today's switch (loki
accountkit-switch.yml). This moves the pages onto AccountKit's screens:
SignInForm, SignUpForm and the recovery form in de/en/fr, AccountPanel on
the profile. Password, passkey, a second factor; the email link and
recovery with mail; OrangeCat and the bitbaum sign-in when their env is set.

What stays Vita's: no delete button (medical records are kept ten years:
accountDeletion: false, and the panel leads to the erasure request); the
name on `users` (ownProfile); the per-account lockout, now a plugin on
AccountKit's sign-in; a new person's users row, profile and welcome
sequence; the role-aware landing. The runtime answers only with
AUTH_RUNTIME=accountkit and is unavailable elsewhere, so it never writes
accounts an import would refuse.

NextAuth, the bridge and Vita's own registration, forgot-, reset- and
change-password routes are gone; AccountKit is the only credential writer.
Production has no Google client and no Google links, so nobody loses a way in.


Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-02 22:44:00 +01:00

42 lines
1.8 KiB
TypeScript

/**
* Vita's accounts, on AccountKit's shared runtime: email and password, an
* email sign-in link, passkeys, two-factor codes, password recovery, Sign in
* with OrangeCat and the shared bitbaum sign-in, each shown when its env is
* set (lib/auth/methods.ts). AccountKit is the only writer of credentials
* (docs/ACCOUNTKIT-MIGRATION.md).
*/
import bcrypt from "bcryptjs";
import { createAuthRuntime } from "@bitbaum/accountkit/auth/next";
import { createAuthMailer } from "@bitbaum/accountkit/auth/mail";
import { COMPANY, PORTAL_URL } from "@/lib/config/company";
import { getInstance } from "@/lib/db";
import { authTables } from "@/lib/db/schema";
import { ensureVitaUser } from "./accounts";
import { vitaPlugin } from "./vita-plugin";
const site = { url: PORTAL_URL, title: COMPANY.name, slug: "vita" };
/** Account mail through the fleet transport (RESEND_*). */
export const sharedAuthMailer = createAuthMailer({ site });
export const sharedAuth = createAuthRuntime({
site,
mail: sharedAuthMailer,
// Only on a switched box (loki accountkit-switch.yml sets AUTH_RUNTIME after
// the import). Anywhere else every auth route answers 503 instead of
// writing accounts the import would then refuse to overwrite.
isDatabaseConfigured: (env) => env.AUTH_RUNTIME === "accountkit" && Boolean(env.DATABASE_URL),
getDatabase: () => getInstance(),
schema: authTables,
// Hashes imported from NextAuth are bcrypt (and AccountKit $bs1$); every
// password set through AccountKit is its native scrypt.
legacyBcrypt: bcrypt,
// users.id is a uuid that 31 tables reference.
ids: "uuid",
onAccountCreated: ensureVitaUser,
// Medical records are kept for ten years (/regulation#instant-deletion): a
// patient asks for erasure (/api/account/deletion-request), never deletes.
accountDeletion: false,
plugins: [vitaPlugin()],
});