mirror of
https://github.com/bitbaum/petvity.git
synced 2026-12-06 02:49:43 +01:00
Petvity moves from Auth.js to @bitbaum/accountkit one reversible step at a time, as evig and kivvi do. Nothing changes while AUTH_RUNTIME is unset. - Migration 0008: AccountKit's tables under an `auth_` prefix, plus the users <-> auth_users mirror functions, inert until attached. - scripts/db/accountkit-import.sql: accounts under their own ids, bcrypt hashes byte for byte, verification kept, orangecat_sub as an `orangecat` account row; refuses collisions, drift or a live shared runtime, then attaches the triggers. The rehearsal CLI always rolls back. - lib/auth/shared/: the runtime (ids: 'uuid', legacy bcrypt, AccountKit 0.16.0), a session reader re-read from `users` on every request, a bridge that answers next-auth/react including "Sign in with OrangeCat", and a Petvity row for a person AccountKit creates itself. AccountKit's own credential endpoints stay closed; Petvity's writers stay the only ones. - lib/auth/claims.ts: the ADMIN_EMAILS promotion rule, written once. - The proxy has one routing function and two session sources. - browser-smoke.yml runs the account journey once per runtime; the AccountKit leg first runs the rehearsal and the real-database journeys. docs/ACCOUNTKIT-MIGRATION.md records what is left before switching. Claude-Session: https://claude.ai/code/session_019MDtmud6zcK4rStBGmYSML Co-authored-by: Claude <noreply@anthropic.com>
19 lines
795 B
TypeScript
19 lines
795 B
TypeScript
import { emailEarnsPromotion } from "@bitbaum/accountkit/orangecat";
|
|
import { resolveRole } from "@/lib/domain/auth";
|
|
import type { UserRole } from "./types";
|
|
|
|
/**
|
|
* The role a sign-in leaves a person with. ADMIN_EMAILS may only PROMOTE, and
|
|
* only at a sign-in whose address the product can trust: resolveRole without
|
|
* an intendedRole answers "pet_owner" for everyone else, and writing that back
|
|
* would demote every vet and sitter. Never for an OrangeCat sign-in, whose
|
|
* address is unverified profile data. One rule for both runtimes.
|
|
*/
|
|
export function roleAfterSignIn(
|
|
provider: string | null | undefined,
|
|
email: string | null | undefined,
|
|
existing: UserRole,
|
|
): UserRole {
|
|
return emailEarnsPromotion(provider) && resolveRole(email ?? "") === "admin" ? "admin" : existing;
|
|
}
|