A complete, production-ready authentication solution built with Next.js 14, Auth.js v5 (NextAuth), Prisma, and PostgreSQL. This project demonstrates modern authentication patterns with a beautiful UI powered by shadcn/ui and Tailwind CSS.
- Credentials Login - Email & password authentication with secure hashing
- OAuth Providers - Google and GitHub social login integration
- Two-Factor Authentication (2FA) - TOTP-based 2FA for enhanced security
- Email Verification - Verify user emails before allowing access
- Password Reset - Secure forgot password flow with email tokens
- 2FA Codes - Email-based two-factor authentication codes
- JWT Sessions - Secure, stateless session management
- Role-Based Access Control - Admin and User roles with protected routes
- CSRF Protection - Built-in protection against cross-site request forgery
- Secure Password Hashing - bcrypt-based password encryption
- Beautiful Landing Page - Modern, responsive design with dark/light mode
- Settings Dashboard - Update profile, change password, enable 2FA
- Role-Based UI - Different views for Admin and User roles
- Toast Notifications - Real-time feedback for user actions
| Category | Technology |
|---|---|
| Framework | Next.js 14 (App Router) |
| Authentication | Auth.js v5 (NextAuth) |
| Database | PostgreSQL |
| ORM | Prisma |
| Styling | Tailwind CSS |
| UI Components | shadcn/ui |
| Email Service | Resend |
| Form Validation | Zod + React Hook Form |
├── actions/ # Server actions for auth operations
├── app/
│ ├── (protected)/ # Protected routes (requires authentication)
│ ├── api/ # API routes
│ └── auth/ # Authentication pages (login, register, etc.)
├── components/
│ ├── auth/ # Authentication components
│ ├── layout/ # Layout and landing page sections
│ └── ui/ # shadcn/ui components
├── data/ # Database query functions
├── hooks/ # Custom React hooks
├── lib/ # Utility functions and configurations
├── prisma/ # Database schema
└── schemas/ # Zod validation schemas
- Clone the repository
git clone https://github.com/SaketKothari/auth-v5.git
cd auth-v5- Install dependencies
npm install- Set up environment variables
Create a .env file in the root directory:
# Database
DATABASE_URL="postgresql://username:password@host:5432/database"
DIRECT_URL="postgresql://username:password@host:5432/database"
# NextAuth
AUTH_SECRET="your-auth-secret" # Run: npx auth secret
# App URL
NEXT_PUBLIC_APP_URL="http://localhost:3000"
# OAuth Providers
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
GITHUB_CLIENT_ID="your-github-client-id"
GITHUB_CLIENT_SECRET="your-github-client-secret"
# Email (Resend)
RESEND_API_KEY="your-resend-api-key"- Set up the database
npx prisma generate
npx prisma db push- Run the development server
npm run dev- Open your browser
Navigate to http://localhost:3000
| Variable | Description | How to Get |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Neon or Supabase |
AUTH_SECRET |
NextAuth secret key | Run npx auth secret |
GOOGLE_CLIENT_ID/SECRET |
Google OAuth credentials | Google Cloud Console |
GITHUB_CLIENT_ID/SECRET |
GitHub OAuth credentials | GitHub Developer Settings |
RESEND_API_KEY |
Email service API key | Resend Dashboard |
Modern, responsive landing page with dark/light mode support.
- Login with credentials or OAuth
- Register with email verification
- Two-factor authentication
- Password reset flow
- User settings management
- Role-based access control
- Profile customization
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- 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 open source and available under the MIT License.
Saket Kothari
- GitHub: @SaketKothari
⭐ If you found this project helpful, please give it a star!