Files
CatoandClaude Opus 5.5 b405b49ae7 feat(auth): account mail through AccountKit's shared mailer, with the sign-in code (#132)
* feat(auth): account mail through AccountKit's shared mailer, with the sign-in code

The account mails stay this app's own words, in the reader's language, with
HTML: the template is handed to createAuthMailer({ render, codes: true })
(AccountKit 0.26.1). The shared mailer checks the link's origin, skips
addresses that cannot receive mail and puts a six-digit code in the sign-in
link's email, which the template prints ("On another device? Type this
code ..."). The sign-in page then offers the field for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

* chore: keep main's AccountKit 0.27.0 (the merge had lowered it)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

---------

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

54 lines
1.9 KiB
TypeScript

import { isStaff } from "@bitbaum/accountkit/auth";
import { createAuthRuntime } from "@bitbaum/accountkit/auth/next";
import { dbConfigured, getDb } from "../db";
import { authMail } from "../mail";
import { SITE } from "../site";
import { adoptLegacyMatters } from "./legacy";
/**
* Accounts for Causius: the same account system as every fleet product
* (@bitbaum/accountkit/auth) — email and password, a link, a passkey, two-step
* codes, and, where configured, the shared bitbaum sign-in and OrangeCat. A
* person does not need an OrangeCat account; with one, it is one click.
*/
export const { GET, POST, getSession, requireUser, authStatus, getAuth } =
createAuthRuntime({
site: SITE,
mail: authMail,
isDatabaseConfigured: () => dbConfigured(),
getDatabase: () => getDb(),
// Matters made while OrangeCat was the only way in belong to the same person.
onAccountCreated: async ({ userId, providerId, accountId }) => {
if (providerId === "orangecat")
await adoptLegacyMatters(getDb(), accountId, userId);
},
});
/**
* The signed-in person as the rest of the app reads them: `actorId` is the
* account's id, kept under the name every call site already uses.
*/
export async function auth(): Promise<{
actorId: string;
user: { name: string; image: string | null };
} | null> {
const session = await getSession();
if (!session) return null;
return {
actorId: session.user.id,
user: { name: session.user.name, image: session.user.image ?? null },
};
}
/**
* The signed-in person if they may review credentials: staff or admin, the
* role only `pnpm run role:grant` (or the Grant role workflow) changes. Nobody
* reviews by holding an email address or by asking.
*/
export async function reviewer(): Promise<{ actorId: string } | null> {
const session = await getSession();
return session && isStaff(session.user.role)
? { actorId: session.user.id }
: null;
}