SuperAPI AI Directory

better-auth

Coding & development

View repository

Updated 10-16 03:46

About this skill

Better Auth Best Practices

Implementation and migration guide for Better Auth, the framework-agnostic TypeScript authentication and authorization library. This skill contains 42 rules organized by impact across 8 categories, derived from the official documentation and migration guides.

When to Apply

Reference these guidelines when:

  • Setting up a fresh Better Auth instance (config, adapter, route handler, client)
  • Wiring framework-specific integrations (Next.js App/Pages Router, SvelteKit, Hono, Express, Nuxt, Astro)
  • Configuring sessions, cookies, and security (rate limit, trusted origins, password hashing)
  • Adding plugins: 2FA, organization, admin, magicLink, JWT, passkey, multi-session
  • Migrating from another auth library (NextAuth/Auth.js, Clerk, Auth0, Supabase Auth)
  • Debugging "session is null" / "redirect_uri_mismatch" / 403 CSRF errors
  • Reviewing PRs that touch lib/auth.ts, auth-client.ts, or /api/auth/ route handlers

Rule Categories by Priority

Priority Category Impact Prefix
1 Setup & Configuration CRITICAL setup-
2 Database Adapters & Schema CRITICAL db-
3 API Route Handlers CRITICAL route-
4 Session & Cookies HIGH session-
5 Auth Methods & Providers HIGH auth-
6 Security & Hardening HIGH security-
7 Plugins & Extensions MEDIUM plugins-
8 Migration from Other Auth MEDIUM migrate-

Quick Reference

1. Setup & Configuration (CRITICAL)

2. Database Adapters & Schema (CRITICAL)

3. API Route Handlers (CRITICAL)

4. Session & Cookies (HIGH)

5. Auth Methods & Providers (HIGH)

6. Security & Hardening (HIGH)

7. Plugins & Extensions (MEDIUM)

8. Migration from Other Auth (MEDIUM)

How to Use

For a fresh implementation, read in priority order: start with all setup- rules, then db-, then route- — these CRITICAL categories must be correct or nothing else works. After the foundation, pick the rules that match your scope: session- for cookie/expiry tuning, auth- for provider configuration, security- for production hardening.

For a migration from another auth library, read migrate-parallel-cutover first (strategy), then security-password-hash-interop (preserve user passwords), then migrate-oauth-account-mapping and migrate-nextauth-schema-mapping (data layout).

Read individual reference files for detailed explanations, incorrect vs. correct code examples, and links to the canonical Better Auth documentation.

Reference Files

File Description
references/_sections.md Category definitions ordered by impact
assets/templates/_template.md Template for adding new rules
metadata.json Version, references, and discipline metadata