A complete, production-ready authentication starter kit for modern web applications built with Next.js 15, Prisma ORM, and NextAuth.js v5.
Building authentication from scratch is time-consuming, error-prone, and security-critical. This boilerplate solves these common challenges:
- Time Waste: Spending weeks implementing auth instead of building your core features
- Security Risks: Missing edge cases, improper session handling, vulnerable endpoints
- Complexity: Managing multiple auth providers, email verification, password resets
- Type Safety: Lack of proper TypeScript integration with auth state
- User Experience: Poor error handling, confusing flows, no loading states
- Maintenance: Hard to update, extend, or debug authentication logic
- Complete Auth System: Sign up, sign in, email verification, password reset
- Multiple Providers: Google OAuth + Email/Password credentials
- Production Ready: Proper error handling, validation, and security measures
- Type Safe: Full TypeScript integration with NextAuth.js
- Modern Stack: Next.js 15 App Router, Prisma ORM, Tailwind CSS
- Best Practices: Follows security and UX best practices
- User Registration with email verification
- User Sign In with credentials or Google OAuth
- Password Reset with secure token-based flow
- Email Verification for new accounts
- Session Management with JWT strategy
- Route Protection with middleware
- Responsive Design with Tailwind CSS
- Loading States and proper error handling
- Form Validation with Zod schemas
- Success/Error Messages for all actions
- Mobile-First dashboard layout
- Password Hashing with bcrypt
- Token Expiration (1 hour for password reset, 24 hours for email verification)
- Route Protection with Next.js middleware
- Input Validation and sanitization
- Secure Session Handling
- Prisma ORM with MySQL support
- Type-Safe Queries and migrations
- Proper Relationships between User, Account, and Session models
- Token Management for verification and password reset
src/
├── app/ # Next.js App Router
│ ├── api/auth/ # Authentication API routes
│ ├── auth/ # Auth pages (signin, register, forgot-password)
│ ├── dashboard/ # Protected dashboard routes
│ └── layout.tsx # Root layout with auth provider
├── components/ # Reusable UI components
│ ├── auth/ # Authentication forms
│ ├── dashboard/ # Dashboard components
│ └── layout/ # Layout components
├── lib/ # Utility libraries
│ ├── auth.ts # NextAuth.js configuration
│ ├── prisma.ts # Prisma client
│ ├── mail.ts # Email utilities
│ └── validations/ # Zod validation schemas
├── hooks/ # Custom React hooks
├── types/ # TypeScript type definitions
└── middleware.ts # Route protection middleware
- Node.js 18+
- MySQL database
- Google OAuth credentials (optional)
- Resend API key for emails
git clone <your-repo-url>
cd nextjs-prisma-auth-boilerplate
npm install
Copy .env.example
to .env
and fill in your values:
# Database
DATABASE_URL="mysql://user:pass@localhost:3306/next_auth_starter"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-strong-random-secret"
# Google OAuth (optional)
GOOGLE_CLIENT_ID="your_google_client_id"
GOOGLE_CLIENT_SECRET="your_google_client_secret"
# Resend (for emails)
RESEND_API_KEY="your_resend_api_key"
EMAIL_FROM="Auth Starter <no-reply@yourdomain.com>"
# Generate Prisma client
npx prisma generate
# Run database migrations
npx prisma db push
# (Optional) Seed database
npx prisma db seed
npm run dev
Visit http://localhost:3000 to see your app!
- Sign Up: Create account with email verification
- Sign In: Use email/password or Google OAuth
- Dashboard: Access protected content after authentication
- Password Reset: Request reset link if forgotten password
- Extend Models: Add fields to User model in Prisma schema
- Add Providers: Configure additional OAuth providers in
lib/auth.ts
- Custom Pages: Modify auth pages in
app/auth/
directory - Add Routes: Create new protected routes in
app/dashboard/
// lib/auth.ts
import GitHubProvider from 'next-auth/providers/github';
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
// ... existing providers
GitHubProvider({
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
}),
],
});
// prisma/schema.prisma
model User {
// ... existing fields
role String @default("USER") // Can be: USER, ADMIN, MODERATOR
}
Modify email templates in src/lib/mail.ts
to match your brand.
# Run linting
npm run lint
# Run type checking
npm run type-check
# Build for production
npm run build
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run format # Format code with Prettier
npm run db:generate # Generate Prisma client
npm run db:push # Push schema to database
npm run db:seed # Seed database with sample data
- Password Hashing: Bcrypt with salt rounds
- Token Expiration: Configurable expiration times
- Route Protection: Middleware-based access control
- Input Validation: Zod schema validation
- Session Security: JWT with proper configuration
- CSRF Protection: Built into NextAuth.js
- Save 2-4 weeks of development time
- Focus on core features instead of auth
- Production-ready from day one
- Security best practices built-in
- Scalable architecture with Prisma
- Type safety throughout the stack
- Professional quality authentication
- Easy customization for client needs
- Modern tech stack that impresses
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- NextAuth.js - Authentication for Next.js
- Prisma - Next-generation ORM
- Tailwind CSS - Utility-first CSS framework
- Next.js - React framework
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: your-email@example.com
Built with ❤️ for the Next.js community
Star this repository if it helped you build something amazing!