Better Auth Implementation Guide
Goal: Implement robust, type-safe authentication with Role-Based Access Control (RBAC) using Better Auth.
Core Capabilities
- •Installation: Setup in Next.js App Router with Prisma.
- •Schema Management: Using
@better-auth/clito auto-generate Prisma schemas. - •Role Management: Implementing tiered roles (Admin, Regional Manager, Centre Manager) via the Organization Plugin.
- •Migration: Moving from other providers (e.g., Clerk) to Better Auth.
Quick Start
1. Installation
Run the following to install the core package and CLI:
npm install better-auth npm install @better-auth/cli --save-dev
See installation.md for full setup instructions including environment variables.
2. Database Adapter (Prisma)
Better Auth requires a specific Prisma schema. Do not manually create this. Use the CLI to generate it based on your config:
npx @better-auth/cli generate
See prisma-adapter.md for details.
3. Role Management (Organization Plugin)
For managing Admins, Regional Managers, and Centre Managers, use the Organization Plugin. See organization-plugin.md for configuration and usage.
4. Migration from Clerk
See migration-guide.md for mapping users and strategies.