AuthFlow is a robust, full‑stack authentication system built with React (frontend) and Node.js + Express + MongoDB (backend). It provides secure user registration and login using JWTs, bcrypt password hashing, protected and role‑based routes, and easy local or cloud deployment.
A robust full-stack authentication system built with React and Node.js
Features • Tech Stack • Installation • API • Security • Author
- 🔒 User Registration & Login: Secure user authentication with JWT tokens
- 🛡️ Password Encryption: Uses bcrypt for secure password hashing
- 🚫 Protected Routes: Client-side and server-side route protection
- 📱 Responsive Design: Modern UI that works on all devices
- 👥 Role-Based Access: Support for user roles (user, admin)
- 💾 Persistent Sessions: Login state persists across browser sessions
| Frontend | Backend |
|---|---|
|
|
/
├── backend/ # Server-side code
│ ├── middleware/
│ │ └── auth.js # Authentication middleware
│ ├── models/
│ │ └── User.js # User model schema
│ ├── routes/
│ │ ├── auth.js # Authentication routes
│ │ └── protected.js # Protected routes
│ ├── .env.example # Environment variables template
│ ├── package.json # Backend dependencies
│ └── server.js # Express server setup
├── frontend/ # Client-side code
│ ├── public/
│ │ └── index.html # HTML template
│ ├── src/
│ │ ├── App.jsx # Main React component
│ │ ├── index.css # Styles
│ │ └── index.jsx # React entry point
│ └── package.json # Frontend dependencies
└── package.json # Root package.json
| Node.js | v14 or higher |
| MongoDB | Local or cloud instance |
| Package Manager | npm or yarn |
Step 1: Clone the repository
git clone https://github.com/abhrajyoti-01/AuthFlow.gitStep 2: Install dependencies
npm run install-allStep 3: Configure environment
cd backend
cp .env.example .envUpdate the .env file with your configuration:
MONGODB_URI=mongodb://127.0.0.1:27017/auth-system
JWT_SECRET=your-super-secret-jwt-key-here
JWT_EXPIRES_IN=7d
PORT=5000Step 4: Start MongoDB
Make sure MongoDB is running on your system or connect to your cloud instance.
Step 5: Run the application
Start the backend server:
npm run dev-backendIn a new terminal, start the frontend:
npm run dev-frontend| Service | URL | Description |
|---|---|---|
| Frontend | http://localhost:3000 | React application |
| Backend API | http://localhost:5000 | Express server |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/auth/register |
Register a new user | No |
POST |
/api/auth/login |
Login user | No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/protected/public |
Public route | No |
GET |
/api/protected/profile |
Get user profile | Yes |
GET |
/api/protected/admin |
Admin only route | Yes + Admin role |
- ✅ Modern React with functional components and hooks
- ✅ React Router for navigation
- ✅ Responsive design with CSS Grid and Flexbox
- ✅ Form validation and error handling
- ✅ JWT token storage and management
- ✅ Protected routes
- ✅ Beautiful UI with animations and transitions
| Feature | Description |
|---|---|
| 🔒 Password Hashing | bcrypt with 12 salt rounds |
| ⏱️ Token Expiration | JWTs expire after configured time |
| 🚫 Protected Routes | Server and client-side protection |
| ✅ Input Validation | Validation and sanitization of all inputs |
| 🔍 Security Headers | Implemented using Helmet middleware |
| 🚦 Rate Limiting | Prevents brute force and DoS attacks |
| 🌐 CORS | Configured for secure cross-origin requests |
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
