A clean and secure authentication system built with Next.js 16, NextAuth.js, and Tailwind CSS.
- Secure Authentication: Built with NextAuth.js for robust session management
- Role-Based Access Control: Admin and Consumer roles with protected routes
- Modern UI: Clean design with dark blue, white, red, and black color palette
- Responsive Design: Works seamlessly across all devices
- Real-time Greetings: Dynamic time-based greetings and live clock
- Session Management: Secure JWT-based sessions with proper logout
- Primary: Dark Blue (#1e3a8a, #1e40af)
- Accent: Red (#dc2626)
- Text: Black (#000000), White (#ffffff)
- Backgrounds: Light (#f8fafc), Dark gradients
nextjs_auth_workflow/
├── app/
│ ├── api/auth/[...nextauth]/ # NextAuth API routes
│ ├── consumer/ # Consumer dashboard
│ ├── dashboard/ # Admin dashboard
│ ├── login/ # Login page
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Home page (redirects)
│ └── providers.tsx # Session provider
├── components/
│ ├── AuthForm.tsx # Login form component
│ └── Navbar.tsx # Navigation component
├── lib/
│ ├── auth.ts # Auth utilities
│ ├── users.json # Demo user data
│ └── validation.ts # Form validation
└── middleware.ts # Route protection
- Admin: admin@example.com / adminpass
- Consumer: consumer@example.com / consumerpass
- Author: author@example.com / authorpass
-
Install dependencies:
npm install
-
Set up environment variables: Create
.env.localwith:NEXTAUTH_SECRET=your-secret-key NEXTAUTH_URL=http://localhost:3000 -
Run the development server:
npm run dev
-
Open your browser: Navigate to http://localhost:3000
- ✅ Removed signup functionality - Only signin is available
- ✅ Enhanced navbar styling with improved color scheme
- ✅ Better dashboard design with greeting messages and real-time clock
- ✅ Consistent color palette throughout the application
- ✅ Improved user experience with loading states and transitions
- ✅ Clean code structure with removed unused components
- ✅ Better typography and spacing
- ✅ Enhanced security with proper route protection
- Unauthenticated users → Redirected to
/login - Successful login → Redirected based on role:
- Admin →
/dashboard - Consumer →
/consumer - Others →
/dashboard
- Admin →
- Protected routes → Middleware checks authentication
- Logout → Secure session termination and redirect to login
- Next.js 16 - React framework
- NextAuth.js - Authentication library
- Tailwind CSS - Utility-first CSS framework
- TypeScript - Type safety
- Zod - Schema validation
- JWT-based sessions
- CSRF protection
- Secure cookie handling
- Route-level protection
- Input validation
- XSS prevention
Built with ❤️ using modern web technologies for a secure and user-friendly authentication experience.