A production-ready authentication starter kit built with Next.js 16, Prisma ORM, and Better Auth featuring multi-role authentication system (User, Provider, Admin).
- π Next.js 16 - Latest App Router with Server Actions
- π Better Auth - Modern authentication library with email & OAuth support
- ποΈ Prisma ORM - Type-safe database access with PostgreSQL
- π₯ Multi-Role System - USER, PROVIDER, and ADMIN roles
- π¨ shadcn/ui - Beautiful, accessible UI components
- π React Hook Form + Zod - Type-safe form validation
- π― TypeScript - Full type safety across the stack
- π Sonner - Toast notifications
- β‘ Optimized - Fast server actions with minimal database queries
- Framework: Next.js 16 (App Router)
- Database: PostgreSQL with Prisma ORM
- Authentication: Better Auth
- Styling: Tailwind CSS
- UI Components: shadcn/ui
- Form Handling: React Hook Form
- Validation: Zod
- Type Safety: TypeScript
- Package Manager: Bun (or npm/pnpm/yarn)
Before you begin, ensure you have the following installed:
- Node.js 18.17 or later
- Bun (recommended) or npm/pnpm/yarn
- PostgreSQL database (local or cloud)
- Git
git clone https://github.com/Rogenecarl/nextjs16-prisma-better-auth-starterkit.git
cd nextjs16-prisma-better-auth-starterkitbun install
# or
npm install
# or
pnpm install
# or
yarn installCreate a .env file in the root directory and add the following:
# Database
DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
DIRECT_URL="postgresql://user:password@localhost:5432/mydb"
# Better Auth
BETTER_AUTH_SECRET="your-super-secret-key-min-32-chars"
BETTER_AUTH_URL="http://localhost:3000"
# Google OAuth (Optional)
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"Important: Replace the placeholder values with your actual credentials.
Run Prisma migrations to create database tables:
bunx prisma migrate dev
# or
npx prisma migrate devGenerate Prisma Client:
bunx prisma generate
# or
npx prisma generatebun dev
# or
npm run dev
# or
pnpm dev
# or
yarn devOpen http://localhost:3000 in your browser to see the application.
project-himsog-next-16/
βββ prisma/
β βββ schema.prisma # Database schema
β βββ migrations/ # Database migrations
βββ src/
β βββ actions/
β β βββ auth/ # Server actions for authentication
β β βββ auth-actions.ts
β β βββ google-auth-actions.ts
β βββ app/ # Next.js App Router
β β βββ auth/ # Authentication pages
β β βββ provider/ # Provider dashboard
β β βββ api/ # API routes
β βββ components/
β β βββ auth/ # Authentication forms
β β βββ ui/ # shadcn/ui components
β β βββ provider-components/
β βββ lib/
β β βββ auth.ts # Better Auth configuration
β β βββ prisma.ts # Prisma client
β β βββ utils/ # Utility functions
β βββ schemas/ # Zod validation schemas
β βββ types/ # TypeScript type definitions
β βββ context/ # React context providers
βββ public/ # Static assets
The application supports three user roles with different access levels:
| Role | Description | Default Route |
|---|---|---|
| USER | Regular user with basic access | /find-services |
| PROVIDER | Service provider with extended features | /provider/dashboard |
| ADMIN | Administrator with full access | /admin/dashboard |
After successful login, users are automatically redirected based on their role:
- Admin β
/admin/dashboard - Provider β
/provider/dashboard - User β
/find-services
- β Email/Password authentication
- β Google OAuth (optional)
- β Role-based access control
- β Automatic role-based redirects
- β Secure session management
- β Password validation
- β Email verification ready
- β Protected routes
# Development
bun dev # Start development server
bun build # Build for production
bun start # Start production server
# Database
bunx prisma studio # Open Prisma Studio (database GUI)
bunx prisma migrate dev # Run migrations
bunx prisma generate # Generate Prisma Client
# Code Quality
bun run lint # Run ESLint
bun run type-check # TypeScript type checkingThe project uses Prisma with the following main models:
User- User accounts with role fieldSession- User sessionsAccount- OAuth accountsVerification- Email verification tokens
- Update the
UserRoleenum inprisma/schema.prisma:
enum UserRole {
USER
ADMIN
PROVIDER
YOUR_NEW_ROLE // Add here
}- Update the redirect map in
src/actions/auth/auth-actions.ts:
const redirectMap = {
ADMIN: "/admin/dashboard",
PROVIDER: "/provider/dashboard",
USER: "/find-services",
YOUR_NEW_ROLE: "/your-route", // Add here
} as const;- Run migration:
bunx prisma migrate dev --name add_new_roleThe project uses Tailwind CSS. Customize colors and themes in:
tailwind.config.ts- Tailwind configurationsrc/app/globals.css- Global styles
All UI components are from shadcn/ui and located in src/components/ui/. Customize them as needed.
- Push your code to GitHub
- Import project to Vercel
- Add environment variables
- Deploy
Ensure all environment variables are set in your deployment platform:
DATABASE_URL- Production database URLDIRECT_URL- Direct database connectionBETTER_AUTH_SECRET- Secure random string (min 32 chars)BETTER_AUTH_URL- Your production URL- OAuth credentials (if using)
- Next.js Documentation
- Prisma Documentation
- Better Auth Documentation
- shadcn/ui Documentation
- Tailwind CSS Documentation
- Server Actions - Modern data mutations without API routes
- Type-Safe Forms - React Hook Form + Zod validation
- Role-Based Auth - Multi-role authentication system
- Optimized Queries - Minimal database calls for performance
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License.
If you encounter any issues, please open an issue on GitHub.
If this project helped you, please give it a βοΈ!
Built with β€οΈ using Next.js 16, Prisma, and Better Auth