A comprehensive authentication system with profile management, social media integration, and real-time features.
- User Registration with automatic username generation
- Secure Login with JWT tokens
- Password Reset functionality
- Token Management with automatic expiration handling
- Protected Routes with authentication guards
- Profile Photo Upload with image validation
- Auto-Generated Username from name/email
- Profile Editing with validation
- Online Status tracking and display
- Social Media Links (GitHub, Twitter, LinkedIn, Website)
- Location & Bio management
- User ID Management with change history
- Modern Dashboard with glass morphism design
- Responsive Design for mobile and desktop
- Real-time Updates without page refresh
- Loading States with proper error handling
- Smooth Animations and transitions
- Mobile Menu with hamburger navigation
- Touch-Friendly interface
- Adaptive Layout for all screen sizes
- React.js with Vite
- Tailwind CSS for styling
- React Router DOM for navigation
- Axios for API calls
- React Hot Toast for notifications
- Lucide React for icons
- Node.js + Express.js
- PostgreSQL database
- Prisma ORM for database management
- JWT for authentication
- bcrypt for password hashing
- dotenv for environment variables
- express-validator for input validation
Auth/
├── client/ # React frontend
│ ├── src/
│ │ ├── components/ # Reusable components
│ │ ├── context/ # React context (Auth)
│ │ ├── pages/ # Page components
│ │ ├── App.jsx # Main app component
│ │ ├── main.jsx # Entry point
│ │ └── index.css # Global styles
│ ├── package.json
│ ├── vite.config.js
│ └── tailwind.config.js
├── server/ # Node.js backend
│ ├── src/
│ │ ├── controllers/ # Route controllers
│ │ ├── middleware/ # Custom middleware
│ │ ├── routes/ # API routes
│ │ └── index.js # Server entry point
│ ├── prisma/
│ │ └── schema.prisma # Database schema
│ ├── package.json
│ └── .env # Environment variables
└── README.md
- Node.js (v16 or higher)
- PostgreSQL (v12 or higher)
- npm or yarn
- Install PostgreSQL on your system
- Create a new database:
CREATE DATABASE authdb;
- Create a user (optional but recommended):
CREATE USER authuser WITH PASSWORD 'yourpassword'; GRANT ALL PRIVILEGES ON DATABASE authdb TO authuser;
-
Navigate to the server directory:
cd server -
Install dependencies:
npm install
-
Configure environment variables:
cp .env.example .env
Edit
.envfile with your database credentials:DATABASE_URL="postgresql://authuser:yourpassword@localhost:5432/authdb?schema=public" JWT_SECRET="your-super-secret-jwt-key-change-this-in-production" JWT_EXPIRES_IN="7d" PORT=5000 NODE_ENV=development FRONTEND_URL="http://localhost:5173"
-
Generate Prisma client:
npm run prisma:generate
-
Run database migrations:
npm run prisma:migrate
-
Start the server:
npm run dev
The server will start on
http://localhost:5000
-
Navigate to the client directory:
cd client -
Install dependencies:
npm install
-
Start the development server:
npm run dev
The frontend will start on
http://localhost:5173
- ✅ User Registration with validation
- ✅ User Login with remember me
- ✅ JWT-based authentication
- ✅ Protected routes
- ✅ Password hashing with bcrypt
- ✅ Session management
- ✅ Automatic logout on token expiration
- ✅ Modern glass morphism UI design
- ✅ Responsive layout (mobile & desktop)
- ✅ Dark mode toggle
- ✅ Form validation with error messages
- ✅ Loading states and spinners
- ✅ Toast notifications
- ✅ Password visibility toggle
- ✅ Protected dashboard with user info
- ✅ RESTful API endpoints
- ✅ Input validation and sanitization
- ✅ Error handling
- ✅ CORS configuration
- ✅ Security middleware
- ✅ Database migrations
POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/me- Get current user (protected)
POST /api/auth/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "Password123"
}Response:
{
"success": true,
"message": "User registered successfully",
"data": {
"user": {
"id": "clx123...",
"name": "John Doe",
"email": "john@example.com",
"createdAt": "2024-01-01T00:00:00.000Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}POST /api/auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "Password123"
}GET /api/auth/me
Authorization: Bearer <your-jwt-token>- Password Hashing: Using bcrypt with salt rounds
- JWT Authentication: Secure token-based authentication
- Input Validation: Server-side validation with express-validator
- CORS Protection: Configured for specific frontend URL
- Error Handling: Proper error responses without sensitive information
- Token Expiration: Configurable JWT expiration time
- Glass Morphism Design: Modern, elegant UI with backdrop blur effects
- Dark Mode: Toggle between light and dark themes
- Responsive Design: Works perfectly on all device sizes
- Smooth Animations: Hover effects and transitions
- Loading States: Visual feedback during API calls
- Toast Notifications: Non-intrusive success/error messages
- Form Validation: Real-time validation feedback
- Install Heroku CLI
- Login to Heroku:
heroku login - Create app:
heroku create your-app-name - Set environment variables:
heroku config:set DATABASE_URL="your-production-db-url" heroku config:set JWT_SECRET="your-production-jwt-secret" heroku config:set NODE_ENV=production
- Deploy:
git push heroku main - Run migrations:
heroku run npm run prisma:migrate
- Build the project:
npm run build - Deploy the
distfolder to your hosting provider - Set environment variables
# Copy the example environment file
cp .env.example .env
# Edit with your configuration
nano .env# Database
DATABASE_URL="postgresql://username:password@localhost:5432/authdb"
# JWT
JWT_SECRET="your-super-secret-jwt-key"
JWT_EXPIRES_IN="7d"
# Server
PORT=5000
NODE_ENV="development"# CORS
CORS_ORIGIN="http://localhost:5173"
# Email
EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT=587
EMAIL_USER="your-email@gmail.com"
EMAIL_PASS="your-app-password"
# File Upload
MAX_FILE_SIZE=5242880
UPLOAD_PATH="./uploads"
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
# Redis (for sessions)
REDIS_URL="redis://localhost:6379"
# Logging
LOG_LEVEL="info"
LOG_FILE="logs/app.log"
# Security
BCRYPT_ROUNDS=12
SESSION_SECRET="your-session-secret"DATABASE_URL="postgresql://username:password@localhost:5432/authdb?schema=public"
JWT_SECRET="your-super-secret-jwt-key-change-this-in-production"
JWT_EXPIRES_IN="7d"
PORT=5000
NODE_ENV=development
FRONTEND_URL="http://localhost:5173"-
Register User:
curl -X POST http://localhost:5000/api/auth/register \ -H "Content-Type: application/json" \ -d '{"name":"John Doe","email":"john@example.com","password":"Password123"}'
-
Login User:
curl -X POST http://localhost:5000/api/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"john@example.com","password":"Password123"}'
-
Get User Info:
curl -X GET http://localhost:5000/api/auth/me \ -H "Authorization: Bearer YOUR_JWT_TOKEN"
-
Database Connection Error:
- Check PostgreSQL is running
- Verify DATABASE_URL in .env file
- Ensure database exists
-
Prisma Migration Error:
- Run
npx prisma generate - Check database connection
- Reset database if needed:
npx prisma migrate reset
- Run
-
CORS Error:
- Verify FRONTEND_URL in .env
- Check both servers are running
-
JWT Token Issues:
- Verify JWT_SECRET is set
- Check token expiration
- Clear browser localStorage
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit changes:
git commit -am 'Add some feature' - Push to branch:
git push origin feature-name - Submit a pull request
If you have any questions or issues, please open an issue on GitHub or contact the development team.
Happy Coding! 🎉