A complete Next.js authentication boilerplate with Prisma (MySQL), NextAuth, and Resend. Features email/password auth with verification, Google login, password reset, protected routes, and a responsive dashboard UI.
See the codeA 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:
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
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!
lib/auth.tsapp/auth/ directoryapp/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
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ for the Next.js community
Star this repository if it helped you build something amazing!
20 commits
TypeScript
98.1%
CSS
1.2%
A complete Next.js authentication boilerplate with Prisma (MySQL), NextAuth, and Resend. Features email/password auth with verification, Google login, password reset, protected routes, and a responsive dashboard UI.
See the codeA 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:
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
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!
lib/auth.tsapp/auth/ directoryapp/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
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ for the Next.js community
Star this repository if it helped you build something amazing!
20 commits
TypeScript
98.1%
CSS
1.2%