A full-stack MERN application with advanced authentication features including JWT tokens, refresh tokens, and secure session management.
- User registration and login
- JWT-based authentication with refresh tokens
- Protected routes
- Password change functionality
- Profile management
- Modern Material-UI interface
- Form validation
- Secure session management
-
Frontend:
- React
- Material-UI
- Formik & Yup for form validation
- React Router for navigation
- Axios for API requests
-
Backend:
- Node.js
- Express
- MongoDB with Mongoose
- JWT for authentication
- bcrypt for password hashing
- Express Validator for input validation
- Node.js (v14 or higher)
- MongoDB
- npm or yarn
-
Clone the repository:
git clone <repository-url> cd modern-auth-solution
-
Install backend dependencies:
npm install
-
Install frontend dependencies:
cd client npm install -
Create a
.envfile in the root directory with the following variables:NODE_ENV=development PORT=5000 MONGO_URI=mongodb://localhost:27017/modern-auth JWT_SECRET=your_jwt_secret_key_here JWT_EXPIRE=1h JWT_REFRESH_SECRET=your_jwt_refresh_secret_key_here JWT_REFRESH_EXPIRE=7d CLIENT_URL=http://localhost:3000
-
Start the backend server:
npm run server
-
In a new terminal, start the frontend development server:
npm run client
-
The application will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
POST /api/auth/register- Register a new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userPOST /api/auth/refresh-token- Refresh access tokenPUT /api/auth/change-password- Change user password
GET /api/user/me- Get current user profilePUT /api/user/update-profile- Update user profile
- JWT tokens for authentication
- Refresh tokens for session management
- Password hashing with bcrypt
- Protected routes
- HTTP-only cookies for refresh tokens
- Input validation
- CORS configuration
- Secure password change functionality
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - 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.