A composable, plugin-first, type-safe, runtime- and database-agnostic authentication library grounded in The Copenhagen Book and Pilcrow Auth, designed with OpenCode-style domain registries and better-result railway error handling.
- Specification: SPEC.md
- Domain Glossary: GLOSSARY.md
- Architecture Decision Records: docs/adr/
| Package | Description |
|---|---|
@auth/contract |
Core domain records, AuthSnapshot, _tag-discriminated AuthError, Standard Schema V1 validators, StorageAdapter AST, and indexed AuthContract types. |
@auth/core |
Kernel (createAuth), topological Plugin DAG & Schema Registry, Split <id>.<secret> SHA-256 Session & Single-Use Step-Up Session engine, WebCrypto/Argon2id semaphore, CookieSink, Sec-Fetch-Site + Origin CSRF validation, and Dual-Transport Procedure runtime (auth.call + auth.handler). |
@auth/plugins |
Official composable plugins: passwordPlugin, stepUpPlugin, emailChallengePlugin, oauthPlugin (+ GitHub/Google/Discord/OIDC presets), totpPlugin, passkeyPlugin, mfaPlugin, organizationPlugin, adminPlugin, and checkPasswordPwned (HIBP k-anonymity). |
@auth/storage-memory |
In-memory StorageAdapter with atomic consumeOne, incrementOne, upsertOne, grouped boolean AST, and snapshot transactions. |
@auth/storage-sqlite |
bun:sqlite StorageAdapter with parameterized SQL AST, DELETE ... RETURNING * atomic consumption, BEGIN IMMEDIATE / SAVEPOINT transactions, and deterministic SQL + Drizzle ORM schema code generators. |
@auth/storage-drizzle |
Multi-dialect (postgres, mysql, sqlite) Drizzle ORM StorageAdapter with runtime schema descriptor (createDrizzleSchemaDescriptor), $1/? AST compilation, MySQL SELECT ... FOR UPDATE atomic fallback, and enlistTransaction. |
@auth/storage-kysely |
Multi-dialect (postgres, mysql, sqlite) Kysely StorageAdapter with parameterized AST compilation, atomic security primitives, and enlistTransaction. |
@auth/client |
Contract-typed RPC client hydrating SerializedResult into better-result Result<T, E>, reactive AuthSnapshot store, normalized tag-invalidated query cache (client.cache), and loop-free BroadcastChannel cross-tab sync. |
@auth/tanstack-start |
TanStack Start server request context, CookieSink response binder, open-redirect sanitizer, beforeLoad route guards (requireAuthenticated, requireAnonymous, requireMfaChallenge), and defense-in-depth server function guards (withServerAuth, withServerStepUp). |
@auth/react |
React hooks & controllers (useAuthSnapshot, useSubject, createActionRunner) bound to @auth/client. |
@auth/solid |
Fine-grained SolidJS signal accessors (snapshot, subject, isAuthenticated) bound to @auth/client. |
@auth/foldkit |
Native Foldkit (Elm Architecture + Effect-TS) adapter: secret-free resolveFoldkitAuthFlags SSR handoff, server & biparser client route guards (init + ChangedUrl), resultToEffectDescriptor, deterministic defineFoldkitAuthCommand (with Story/Scene test resolveSuccess/resolveFailure), and gated createFoldkitSessionSubscription. |
@auth/cli |
Schema codegen CLI (drizzle-pg, drizzle-sqlite, prisma-postgresql, prisma-sqlite, sql-postgres, sql-sqlite) and live database schema diff verifier (verifySchemaDiff, inspectSqliteTables). |
@auth/test-kit |
FakeClock, createDeterministicCryptoProvider, and the 25-way concurrent runStorageAdapterConformanceSuite. |
import { Database } from "bun:sqlite" import { createAuth } from "@auth/core" import { createSqliteStorageAdapter } from "@auth/storage-sqlite" import { passwordPlugin, stepUpPlugin, emailChallengePlugin, totpPlugin, passkeyPlugin, mfaPlugin, organizationPlugin, checkPasswordPwned, } from "@auth/plugins" const db = new Database("auth.sqlite") export const auth = createAuth({ storage: createSqliteStorageAdapter(db), plugins: [ passwordPlugin({ checkBreachedPassword: (pw) => checkPasswordPwned(pw), }), stepUpPlugin(), emailChallengePlugin({ onSendCode: async ({ email, code }) => { console.log(`Verification code for ${email}: ${code}`) }, }), totpPlugin({ issuer: "MyApp" }), passkeyPlugin({ rpId: "example.com", rpName: "MyApp", origin: "https://example.com" }), mfaPlugin(), organizationPlugin(), ] as const, }) export type AppAuthContract = typeof auth.contract
// 1. Standard Web Fetch Handler (Bun.serve, Hono, TanStack Start API route, Cloudflare Workers) export default { fetch: (req: Request) => auth.handler(req), } // 2. Direct zero-HTTP call in SSR loaders or server functions (returns a better-result Result) const signInResult = await auth.call.password.signIn( { email: "[email protected]", password: "correct-horse-battery-staple" }, { request }, ) signInResult.match({ ok: ({ snapshot }) => console.log("Signed in subject:", snapshot.subject?.id), err: (error) => console.error(`Auth error [${error._tag}]: ${error.message}`), })
import { createAuthClient } from "@auth/client" import { auth } from "./auth.ts" export const authClient = createAuthClient({ contract: auth.contract, baseURL: "http://localhost:3000", }) // Full autocomplete & typed better-result Result<TOutput, AuthError<TErrors>> const res = await authClient.call.password.signUp({ email: "[email protected]", password: "correct-horse-battery-staple", displayName: "Alice", }) if (res.isOk()) { // Reactive store updates synchronously from the mutation payload (no extra GET /session waterfall) console.log(authClient.store.snapshot.get()) }
# Run the full test suite with Bun's native test runner bun test # Run strict TypeScript typecheck across all 12 workspace packages bun run typecheck