A comprehensive community platform built with Next.js 15, featuring a complete authentication system with NextAuth.js, MongoDB, email verification, role-based access control, and admin approval workflows.
- NextAuth.js with Credentials Provider - Secure email/password authentication
- Email Verification - Required for all users before login
- Role-Based Access Control - Three roles:
admin,volunteer,citizen - Admin Approval Workflow - Volunteers require admin approval before login
- Password Reset - Secure password reset via email links
- Account Management - Users can update profile and change passwords
- Account Deletion - Users can delete their accounts from settings
-
Admin (
shreejaybhay26@gmail.com)- Hardcoded admin user
- Access to admin dashboard
- Can approve/reject volunteer applications
- Full platform management access
-
Volunteer
- Must verify email after registration
- Requires admin approval before login
- Access to volunteer features once approved
-
Citizen
- Must verify email after registration
- Auto-approved (no admin approval needed)
- Access to community features once verified
- JWT Session Strategy - Secure session management
- Password Hashing - bcryptjs with salt rounds
- Route Protection - Middleware-based route protection
- Email Verification Tokens - Secure token-based email verification
- Password Reset Tokens - Time-limited password reset tokens
- Form Validation - Zod schema validation with react-hook-form
- Toast Notifications - Real-time feedback for all operations
- Loading States - Visual feedback during async operations
- Error Handling - Comprehensive error handling and user feedback
- Responsive Design - Mobile-first responsive design
- Smooth Animations - Framer Motion animations throughout
- Frontend: Next.js 15, React 19, Tailwind CSS, Framer Motion
- Authentication: NextAuth.js v5 (beta)
- Database: MongoDB with Mongoose ODM
- Email: Nodemailer with SMTP
- Validation: Zod + React Hook Form
- UI Components: Radix UI primitives
- Styling: Tailwind CSS with custom design system
- Node.js 18+
- MongoDB (local or cloud)
- SMTP email service (Gmail, SendGrid, etc.)
git clone <repository-url>
cd civicnpm installCopy the example environment file and configure your settings:
cp .env.example .env.localUpdate .env.local with your configuration:
# Database
MONGODB_URI=mongodb://localhost:27017/civic-app
# NextAuth.js
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-super-secret-key-change-this-in-production
# Admin Configuration
ADMIN_EMAIL=shreejaybhay26@gmail.com
# Email Configuration (Gmail example)
EMAIL_SERVER_HOST=smtp.gmail.com
EMAIL_SERVER_PORT=587
EMAIL_SERVER_USER=your-email@gmail.com
EMAIL_SERVER_PASSWORD=your-app-password
EMAIL_FROM=your-email@gmail.com
# App Configuration
APP_NAME=ConnectAid
APP_URL=http://localhost:3000Make sure MongoDB is running locally or update MONGODB_URI to point to your MongoDB instance.
For Gmail SMTP:
- Enable 2-factor authentication on your Google account
- Generate an App Password for your application
- Use the App Password in
EMAIL_SERVER_PASSWORD
npm run devOpen http://localhost:3000 to see the application.
The admin user is hardcoded with email shreejaybhay26@gmail.com. To test admin features:
- Register with the admin email
- Verify email through the verification link
- Login to access admin dashboard at
/admin/dashboard
- Go to
/register - Fill out the form and select "Get Help" (citizen role)
- Submit the form
- Check email for verification link
- Click verification link
- Login at
/login - Access dashboard at
/dashboard
- Go to
/register - Fill out the form and select "Volunteer"
- Submit the form
- Check email for verification link
- Click verification link
- Try to login - should show "pending approval" message
- Login as admin and go to
/admin/volunteers - Approve the volunteer application
- Volunteer can now login and access dashboard
- Go to
/forgot-password - Enter email address
- Check email for reset link
- Click reset link to go to
/reset-password - Enter new password
- Login with new password
- Login and go to
/dashboard/settings - Test profile updates
- Test password change
- Test account deletion
src/
βββ app/ # Next.js App Router
β βββ api/ # API Routes
β β βββ auth/ # Authentication endpoints
β β βββ admin/ # Admin-only endpoints
β β βββ user/ # User management endpoints
β βββ admin/ # Admin dashboard pages
β βββ dashboard/ # User dashboard pages
β βββ login/ # Login page
β βββ register/ # Registration page
β βββ forgot-password/ # Forgot password page
β βββ reset-password/ # Reset password page
βββ components/ # React components
β βββ ui/ # UI components
β βββ providers/ # Context providers
βββ lib/ # Utility libraries
β βββ auth.js # NextAuth configuration
β βββ mongodb.js # Database connection
β βββ email.js # Email service
β βββ validations.js # Zod schemas
βββ models/ # Mongoose models
β βββ User.js # User model
β βββ VerificationToken.js # Token model
βββ hooks/ # Custom React hooks
βββ middleware.js # Route protection middleware
POST /api/auth/register- User registrationPOST /api/auth/verify-email- Email verificationGET /api/auth/verify-email?token=- Email verification via URLPOST /api/auth/forgot-password- Request password resetPOST /api/auth/reset-password- Reset passwordGET /api/auth/reset-password?token=- Verify reset token
GET /api/user/profile- Get user profilePUT /api/user/profile- Update user profileDELETE /api/user/profile- Delete user accountPOST /api/user/change-password- Change password
GET /api/admin/volunteers- Get pending volunteersPOST /api/admin/volunteers- Approve/reject volunteers
The application uses a custom design system built with:
- Tailwind CSS for styling
- Radix UI for accessible primitives
- Framer Motion for animations
- Custom color palette with orange/yellow primary colors
- Responsive design with mobile-first approach
- Passwords are hashed with bcryptjs (12 salt rounds)
- JWT tokens are signed and verified
- Email verification prevents unauthorized access
- Rate limiting should be implemented for production
- HTTPS should be used in production
- Environment variables should be properly secured
Make sure to set all environment variables in your production environment:
- Use a strong
NEXTAUTH_SECRET - Update
NEXTAUTH_URLto your production URL - Use a production MongoDB instance
- Configure production email service
- Update
APP_URLto your production domain
- Vercel - Seamless Next.js deployment
- Netlify - Alternative deployment platform
- Railway - Full-stack deployment with database
- DigitalOcean App Platform - Scalable deployment
This project is licensed under the MIT License.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For support or questions, please open an issue in the repository.