This is the Better Auth repository - a comprehensive authentication framework for TypeScript, designed to be runtime and framework-agnostic.
packages/better-auth- Main authentication librarypackages/core- Shared core types and utilitiespackages/cli- CLI toolpackages/*- Database adapters, plugins, integrationsdocs/- Documentation site (Next.js + Fumadocs), content indocs/content/docs/test/- Shared test workspacee2e/- End-to-end tests (smoke, adapter, integration)demo/- Example apps
- ALWAYS use
pnpm(never npm, yarn, or bun) - NEVER run
pnpm test(runs all packages). Usevitest path/to/test -t <pattern> - Type check:
pnpm typecheck - Formatting/linting runs automatically on commit (Lefthook + Biome). No need to run manually.
- Must work across Node.js, Bun, Deno, and Cloudflare Workers. Avoid runtime-specific APIs.
- Biome (tabs for code, 2 spaces for JSON)
- NEVER use
any. NEVER use classes. - Use
Uint8Arrayinstead ofBuffer(except in tests) - Import zod as
import * as z from "zod" - Use
import typefor type-only imports - Use
node:protocol for Node.js built-ins (e.g.node:crypto) - JSDoc comments for public APIs
- Plugins should be as independent as possible. When working on a plugin, prefer modifying the plugin over changing core.
- Most tests use Vitest; some under
e2e/use Playwright - Use
getTestInstance()frombetter-auth/test. It returns{ client, auth, sessionSetter, ... } - Pass client plugins via
clientOptions.plugins - NEVER create separate clients with
createAuthClient()in tests - Default test DB is SQLite in-memory; use
testWithfor other databases - Adapter tests need Docker:
docker compose up -d - Regression tests: add
@seecomment with issue URL aboveit()ordescribe():/** * @see https://github.com/better-auth/better-auth/issues/{issue_number} */ it("should handle the previously broken behavior", async () => { // ... });
- Bug fixes and new features MUST include tests
- For bug fixes: if the issue is reproducible in a test, write a failing test first, then implement the fix
- Update docs (
docs/content/docs/) when changing public API - Ensure
pnpm typecheckpasses before finishing - DO NOT COMMIT unless the user explicitly asks
- Conventional Commits:
feat(scope):,fix(scope):,docs:,chore:. Use!for breaking changes (e.g.feat(auth)!:) - PRs target
main