Files
CatoandClaude Opus 5.5 5a79056056 feat: the shared bitbaum sign-in (OIDC provider, pairwise subjects) (#1)
* feat: the shared bitbaum sign-in (OIDC provider, pairwise subjects)

One OIDC provider holding the Google, Apple, GitHub, X and Meta
credentials once, for every accountkit app (fleet STACK.md, "Identity"):

- better-auth 1.7 + @better-auth/oauth-provider + jwt (RS256); discovery
  at the origin, authorize with PKCE S256 required, token with
  client_secret_post, userinfo, JWKS
- pairwise subject per app (HMAC of redirect host + user); the email
  scope is answered with a per-app .invalid placeholder
- upstream providers each on only when all their env is set, asked for
  no email and no profile; provider tokens are never stored
- consent-free first-party clients from a registry (lib/clients.ts),
  synced at start from per-app secrets in env
- one pairwise-subject derivation (lib/subject.ts), pinned to a literal,
  with a persona input for future non-root lives only
- tests: PKCE flow end to end against fake upstreams, pairwise sub
  differs per app and is stable per app, two providers reporting one
  verified address stay two people, and accountkit's real runtime
  signs in with SIGNIN_* env alone

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

* build: standalone output for the self-host deploy

loki deploy.sh ships .next/standalone and stops without it.

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

* ci: browser smoke on the production build

The fleet rollout gate holds any consumer of a shared package (accountkit,
design-tokens, limitkit) until ci.yml and browser-smoke.yml pass on the
commit. This one starts the production build against PostgreSQL built from
drizzle/ and drives Chromium through a real authorize request from Solon:
health with the database up, discovery for the given issuer, and the app's
sign-in page at 390px with no sideways scroll and no console errors.

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-10-30 23:32:31 +01:00

30 lines
1006 B
TypeScript

import "server-only";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { createSigninAuth, type SigninAuth } from "./auth";
import { getDb, schema } from "./db/client";
import { createSigninHandler } from "./http";
/**
* One auth instance per process, rebuilt monthly: Apple's client secret is a
* JWT minted at build time of the instance and Apple caps it at six months.
*/
const REBUILD_AFTER_MS = 30 * 24 * 60 * 60 * 1000;
let current: { built: number; auth: Promise<SigninAuth> } | null = null;
export function getAuth(): Promise<SigninAuth> {
if (!current || Date.now() - current.built > REBUILD_AFTER_MS) {
const auth = createSigninAuth({
database: drizzleAdapter(getDb(), { provider: "pg", schema }),
});
current = { built: Date.now(), auth };
auth.catch(() => {
current = null;
});
}
return current.auth;
}
export async function handle(request: Request): Promise<Response> {
return createSigninHandler(await getAuth())(request);
}