A modern, secure, and responsive user authentication system built with Next.js, NextAuth.js, and Prisma.
- 🔐 Email/Password authentication
- 🌐 Google OAuth integration
- 🛡️ Protected routes with middleware
- ✨ Modern UI with Tailwind CSS
- 📱 Fully responsive design
- 🔄 Real-time form validation
- 🚀 Server-side rendering
- 🛠️ TypeScript support
- 🔄 Session management
- 🔄 Password hashing with bcrypt
- 🛡️ XSS protection
- ⏱️ Rate limiting
- Frontend: Next.js 14, React 18, TypeScript, Tailwind CSS
- Backend: Next.js API Routes
- Authentication: NextAuth.js
- Database: PostgreSQL with Prisma ORM
- Styling: Tailwind CSS, Framer Motion
- Form Handling: React Hook Form with Zod validation
- Icons: Lucide React
- Node.js 18.0.0 or later
- npm or yarn
- PostgreSQL database
- Google OAuth credentials (for Google Sign-In)
-
Clone the repository
git clone https://github.com/yourusername/users-authentication.git cd users-authentication -
Install dependencies
npm install # or yarn install -
Set up environment variables Create a
.env.localfile in the root directory and add the following variables:DATABASE_URL="postgresql://user:password@localhost:5432/yourdb" NEXTAUTH_SECRET=your-secret-key NEXTAUTH_URL=http://localhost:3000 # Google OAuth GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret # Mailgun SMTP EMAIL_SERVER_HOST=smtp.your-email-server-host EMAIL_SERVER_PORT=your-email-server-port EMAIL_SERVER_USER=your-email-server-user EMAIL_SERVER_PASSWORD=your-email-server-password EMAIL_FROM=your-email-from
-
Set up the database
npx prisma generate npx prisma migrate dev
-
Run the development server
npm run dev # or yarn devOpen http://localhost:3000 in your browser to see the application.
.
├── app/
│ ├── (auth)/ # Authentication pages
│ │ ├── sign-in/ # Sign in page
│ │ └── sign-up/ # Sign up page
│ ├── api/ # API routes
│ │ └── auth/ # Authentication API routes
│ ├── dashboard/ # Protected dashboard
│ └── profile/ # User profile
├── components/ # Reusable components
├── lib/ # Utility functions
├── prisma/ # Prisma schema and migrations
└── public/ # Static files
- Password hashing with bcrypt
- CSRF protection
- Rate limiting on authentication endpoints
- Secure HTTP headers
- XSS protection
- Secure session management
- Environment variable validation
- 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