Better Auth - Complete Authentication
TypeScript-first authentication library with 40+ OAuth providers and 20+ plugins.
Agent Workflow (MANDATORY)
Before ANY implementation, use TeamCreate to spawn 3 agents:
- fuse-ai-pilot:explore-codebase - Analyze existing auth setup and patterns
- fuse-ai-pilot:research-expert - Verify latest Better Auth docs via Context7/Exa
- mcp__context7__query-docs - Check providers/plugins availability
After implementation, run fuse-ai-pilot:sniper for validation.
Overview
When to Use
- Implementing authentication in TypeScript/JavaScript applications
- Need OAuth providers (Google, GitHub, Discord, Apple, Microsoft, etc.)
- Adding 2FA, magic links, passkeys, or phone authentication
- Enterprise SSO with SAML, SCIM provisioning, or organizations
- Integrating payments with Stripe or Polar subscriptions
- Web3 authentication with Sign-In with Ethereum (SIWE)
- Migrating from Auth.js, Clerk, Auth0, Supabase, or WorkOS
Why Better Auth
| Feature |
Benefit |
| Framework agnostic |
Next.js, SvelteKit, Nuxt, Remix, Astro, Expo, NestJS |
| Plugin architecture |
Add only the features you need (20+ plugins) |
| Full TypeScript |
End-to-end type safety, inference included |
| Self-hosted |
Your data stays on your infrastructure |
| Database flexible |
Prisma, Drizzle, MongoDB, PostgreSQL, MySQL, SQLite |
| Enterprise ready |
SSO, SCIM, organizations, audit logs |
Coverage
OAuth Providers (40+)
Google, GitHub, Discord, Apple, Microsoft, Slack, Spotify, Twitter/X, Facebook, LinkedIn, GitLab, Bitbucket, Dropbox, Twitch, Reddit, TikTok, and 25+ more documented in providers/.
Plugins (20+)
| Plugin |
Purpose |
| 2FA |
TOTP authenticator, backup codes |
| Magic Link |
Passwordless email login |
| Passkey |
WebAuthn biometric authentication |
| Organization |
Multi-tenant, roles, invitations |
| SSO |
Enterprise SAML/OIDC single sign-on |
| SCIM |
Directory sync, user provisioning |
| Stripe |
Subscription billing integration |
| API Key |
Machine-to-machine authentication |
| JWT/Bearer |
Token-based API authentication |
Database Adapters
Prisma, Drizzle, MongoDB, raw SQL (PostgreSQL, MySQL, SQLite), and community adapters.
SOLID Architecture (Next.js 16)
Components organized in modules/auth/ following separation of concerns:
- Services:
betterAuth configuration and initialization
- Hooks:
createAuthClient for client-side auth state
- API Route:
app/api/auth/[...all]/route.ts handler
- Proxy:
proxy.ts for route protection (replaces middleware)
Reference Guide
| Need |
Reference |
| Initial setup |
installation.md, server-config.md |
| Client usage |
client.md, session.md |
| OAuth providers |
providers/overview.md, individual provider docs |
| Add plugins |
plugins/overview.md, individual plugin docs |
| Database setup |
adapters/prisma.md, adapters/drizzle.md |
| Enterprise SSO |
plugins/sso.md, guides/saml-okta.md |
| Payments |
plugins/stripe.md, plugins/polar.md |
| Migration |
guides/clerk-migration.md, other migration guides |
| Complete examples |
examples/ for full implementations |
Best Practices
- Plugins on demand - Only add plugins you actually need
- Type-safe client - Use generated types from server config
- Session caching - Enable session caching for performance
- Rate limiting - Configure rate limits for auth endpoints
- Secure cookies - Use secure, httpOnly, sameSite cookies
- Database indexes - Add indexes on user lookup fields
Concepts
Core concepts explained in concepts/:
- Sessions - Token management, refresh, revocation
- Database - Schema design, migrations, adapters
- Plugins - Extension system, composition
- OAuth - Provider configuration, callbacks
- Security - CSRF, rate limiting, password hashing
- Cookies - Session storage, cross-domain
1---2name: better-auth-33description: Complete Better Auth - 40+ OAuth providers, 20+ plugins, all adapters, all frameworks. Use when implementing authentication, login, OAuth, 2FA, magic links, SSO, Stripe, SCIM, or session management.4---5
6# Better Auth - Complete Authentication
7
8TypeScript-first authentication library with 40+ OAuth providers and 20+ plugins.
9
10## Agent Workflow (MANDATORY)
11
12Before ANY implementation, use `TeamCreate` to spawn 3 agents:
13
141. **fuse-ai-pilot:explore-codebase** - Analyze existing auth setup and patterns
152. **fuse-ai-pilot:research-expert** - Verify latest Better Auth docs via Context7/Exa
163. **mcp__context7__query-docs** - Check providers/plugins availability
17
18After implementation, run **fuse-ai-pilot:sniper** for validation.
19
20---
21
22## Overview
23
24### When to Use
25
26- Implementing authentication in TypeScript/JavaScript applications
27- Need OAuth providers (Google, GitHub, Discord, Apple, Microsoft, etc.)
28- Adding 2FA, magic links, passkeys, or phone authentication
29- Enterprise SSO with SAML, SCIM provisioning, or organizations
30- Integrating payments with Stripe or Polar subscriptions
31- Web3 authentication with Sign-In with Ethereum (SIWE)
32- Migrating from Auth.js, Clerk, Auth0, Supabase, or WorkOS
33
34### Why Better Auth
35
36| Feature | Benefit |
37|---------|---------|
38| Framework agnostic | Next.js, SvelteKit, Nuxt, Remix, Astro, Expo, NestJS |
39| Plugin architecture | Add only the features you need (20+ plugins) |
40| Full TypeScript | End-to-end type safety, inference included |
41| Self-hosted | Your data stays on your infrastructure |
42| Database flexible | Prisma, Drizzle, MongoDB, PostgreSQL, MySQL, SQLite |
43| Enterprise ready | SSO, SCIM, organizations, audit logs |
44
45---
46
47## Coverage
48
49### OAuth Providers (40+)
50
51Google, GitHub, Discord, Apple, Microsoft, Slack, Spotify, Twitter/X, Facebook, LinkedIn, GitLab, Bitbucket, Dropbox, Twitch, Reddit, TikTok, and 25+ more documented in [providers/](references/providers/).
52
53### Plugins (20+)
54
55| Plugin | Purpose |
56|--------|---------|
57| 2FA | TOTP authenticator, backup codes |
58| Magic Link | Passwordless email login |
59| Passkey | WebAuthn biometric authentication |
60| Organization | Multi-tenant, roles, invitations |
61| SSO | Enterprise SAML/OIDC single sign-on |
62| SCIM | Directory sync, user provisioning |
63| Stripe | Subscription billing integration |
64| API Key | Machine-to-machine authentication |
65| JWT/Bearer | Token-based API authentication |
66
67### Database Adapters
68
69Prisma, Drizzle, MongoDB, raw SQL (PostgreSQL, MySQL, SQLite), and community adapters.
70
71---
72
73## SOLID Architecture (Next.js 16)
74
75Components organized in `modules/auth/` following separation of concerns:
76
77- **Services**: `betterAuth` configuration and initialization
78- **Hooks**: `createAuthClient` for client-side auth state
79- **API Route**: `app/api/auth/[...all]/route.ts` handler
80- **Proxy**: `proxy.ts` for route protection (replaces middleware)
81
82---
83
84## Reference Guide
85
86| Need | Reference |
87|------|-----------|
88| Initial setup | [installation.md](references/installation.md), [server-config.md](references/server-config.md) |
89| Client usage | [client.md](references/client.md), [session.md](references/session.md) |
90| OAuth providers | [providers/overview.md](references/providers/overview.md), individual provider docs |
91| Add plugins | [plugins/overview.md](references/plugins/overview.md), individual plugin docs |
92| Database setup | [adapters/prisma.md](references/adapters/prisma.md), [adapters/drizzle.md](references/adapters/drizzle.md) |
93| Enterprise SSO | [plugins/sso.md](references/plugins/sso.md), [guides/saml-okta.md](references/guides/saml-okta.md) |
94| Payments | [plugins/stripe.md](references/plugins/stripe.md), [plugins/polar.md](references/plugins/polar.md) |
95| Migration | [guides/clerk-migration.md](references/guides/clerk-migration.md), other migration guides |
96| Complete examples | [examples/](references/examples/) for full implementations |
97
98---
99
100## Best Practices
101
1021. **Plugins on demand** - Only add plugins you actually need
1032. **Type-safe client** - Use generated types from server config
1043. **Session caching** - Enable session caching for performance
1054. **Rate limiting** - Configure rate limits for auth endpoints
1065. **Secure cookies** - Use secure, httpOnly, sameSite cookies
1076. **Database indexes** - Add indexes on user lookup fields
108
109---
110
111## Concepts
112
113Core concepts explained in [concepts/](references/concepts/):
114
115- **Sessions** - Token management, refresh, revocation
116- **Database** - Schema design, migrations, adapters
117- **Plugins** - Extension system, composition
118- **OAuth** - Provider configuration, callbacks
119- **Security** - CSRF, rate limiting, password hashing
120- **Cookies** - Session storage, cross-domain