Nine apps hand-rolled OrangeCat OIDC; this is the best of each: - provider for Auth.js v5 and next-auth v4: client_secret_post, pkce+state, identity scopes; profile() without email (contactEmail as data) - syncOcSession (heidi/solon refresh): invalid_grant ends the session, anything else retries in 60 s - authorizationParams / returnPath (solon) - placeholder email, withOrangecatIdentity adapter wrapper and resolveOrangecatUser (petvity, surf-your-life, datacat race), decideOrangecatSignIn + link token (evig), emailEarnsPromotion, mayReceivePasswordReset - SignInError: Try again restarts sign-in Contract tests mutated: basic auth, dropped pkce, email in profile, ignored invalid_grant, kept actorId, reused taken email, admin promotion, reset for OC-only — each turns the suite red. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@bitbaum/accountkit
One account for every bitbaum product: the account menu (who is signed in, where to go, how to sign out), and Sign in with OrangeCat (@bitbaum/accountkit/orangecat).
Each product had written its own — Loki's AccountMenu, OrangeCat's UserProfileDropdown — and each had learned half of what the other had. Loki took initials only from the name; OrangeCat never rebuilt a name from the email address; OrangeCat had arrow keys and a 44px target, Loki had neither; Loki's public pages had no menu at all, so a signed-in person could not find sign-out. This is the one menu, with both halves.
It knows nothing about how you sign in. NextAuth, Supabase, better-auth: you pass the person, the places, and a sign-out function.
Install
pnpm add github:bitbaum/accountkit#v0.2.0
dist/ is committed, so the github: install needs no build step and no allowBuilds entry.
import "@bitbaum/accountkit/styles.css";
import { AccountMenu } from "@bitbaum/accountkit";
Use
<AccountMenu
user={{ name: session.user.name, email: session.user.email, image: session.user.image }}
groups={[{ id: "nav", items: [{ id: "settings", label: "Settings", href: "/settings" }] }]}
extra={<ThemeToggle />}
onSignOut={() => signOut({ callbackUrl: "/sign-in" })}
renderLink={(props) => <Link {...props} />}
/>
onSignOutmay return a promise. While it runs the row says so; if it rejects, the menu stays open and says sign-out did not complete. A sign-out that fails silently is the one thing this menu must never do.renderLinkkeeps your router (Next<Link>); the default is a plain<a>.extrais for rows that are not places, such as a theme switch.labelstranslates every string:labels={{ trigger: "Konto: {name}", signOut: "Abmelden" }}.
What is shared, and not configurable
- The name is never built from the email. No name:
@handle. No handle: "Account". - Initials come from the name only. No name and no photo: a person glyph.
- A photo that fails to load falls back to initials, then the glyph.
- 44px trigger and rows. The panel never runs off a 320–390px screen.
- Escape closes and returns focus to the trigger, wherever focus was. Arrows, Home and End move between items. A click outside closes.
Theming
Every colour, radius and font is an --acct-* variable. The defaults read @bitbaum/design-tokens at zero specificity, so apps on those tokens match with no work and an app's own :root always wins. An app whose tokens are full colours rather than HSL triplets (Loki's are OKLCH) maps them once:
:root {
--acct-panel: var(--surface-overlay);
--acct-fg: var(--text-primary);
/* … */
}
Verify
pnpm run verify # format, lint, types, build, unit + render tests, real-browser checks
The browser checks run the demo at 390px in light and dark: 44px targets, no sideways scroll with the menu open, Escape after a mouse open, arrow keys, outside click, a broken photo, an anonymous account, and a failing sign-out.
Sign in with OrangeCat — @bitbaum/accountkit/orangecat
Nine apps wrote this themselves and each learned something the others had not. This is all of it, once. Server-only, no next-auth import (the types are structural), so it serves Auth.js v5 and next-auth v4.
import { orangecatClient, orangecatProvider, syncOcSession } from "@bitbaum/accountkit/orangecat";
const orangecat = orangecatClient(); // ORANGECAT_OAUTH_CLIENT_ID / _SECRET / _ISSUER, or null
export const { handlers, auth, signIn, signOut } = NextAuth({
session: { strategy: "jwt" },
pages: { error: "/auth/error" },
providers: orangecat ? [orangecatProvider(orangecat)] : [],
callbacks: {
jwt: ({ token, account, profile }) => syncOcSession({ token, account, profile }, orangecat),
session: ({ session, token }) => ({ ...session, actorId: token.actorId }),
},
});
What is not configurable, and why:
client_secret_postand PKCE. OrangeCat's token endpoint accepts onlyclient_secret_post; the Auth.js default is answered with a 400 that reads "client_id is required". PKCE is required even with a secret.profile()has noemail. OrangeCat auto-confirms addresses, soemail_verifiedproves nothing. With anemail, Auth.js looks a new account up by it and either links (takeover) or refuses. The address rides along ascontactEmail, contact data only. The identity issub(token.actorId), never the email.- A revoked grant ends the session.
syncOcSessionrefreshes once the access token expires;invalid_grantdropsactorId(read that, nevertoken.sub, as "signed in"); any other failure keeps the session and retries in 60 s. Safe insidejwt()since orangecat#1212 (confidential clients keep their refresh token).
Entry: signIn("orangecat", { redirectTo: returnPath(from) }, authorizationParams({ mode, email, provider })) → prompt=create, login_hint, idp_hint (google, github — the providers OrangeCat has switched on). returnPath accepts only same-origin paths.
Apps with their own user table:
withOrangecatIdentity(adapter, store, { keepTokens })— an OrangeCat sign-in resolves bysubalone; a new sub always creates a new user, stored with its OrangeCat address when free andorangecat-<sub>@users.invalidwhen taken. Linking an existing account is Auth.js's own path (sign in, then sign in with OrangeCat).keepTokens: truealso writes the accounts row (for an app that calls OrangeCat on the person's behalf).resolveOrangecatUser(store, identity)— the same, for a callback (next-auth v4, no adapter). Survives the insert race.decideOrangecatSignIn(input, policy)— the pure rule, withwhenEmailTaken/whenNoEmail: "refuse"for an app that prefers to send the person to connect from their profile.mintLinkToken/readLinkToken— evig's "Connect OrangeCat": a 10-minute signed cookie set from inside the session, so the identity that comes back attaches to that account and no other.emailEarnsPromotion(provider)— never ADMIN_EMAILS promotion for an OrangeCat login.mayReceivePasswordReset({ email, hasPassword, orangecatLinked })— no reset link for an account OrangeCat created, or for a placeholder.
The error screen
import { SignInError } from "@bitbaum/accountkit";
// app/auth/error/page.tsx — Auth.js `pages.error`
<SignInError error={searchParams.error} retry={restartSignIn} retryFields={{ from }} home="/" />
Try again restarts sign-in (a server action calling signIn("orangecat", …), or a GET route that does). It never goes home, and it never prints the provider's error code. No hooks: renders in a server component.
MIT.