This project demonstrates a robust user authentication system using the MERN stack (MongoDB, Express.js, React.js, Node.js). It includes features such as user registration, login, and secure access to protected routes.
- User Registration: New users can create an account.
- User Login: Existing users can log in to access protected resources.
- JWT Authentication: Secure user sessions using JSON Web Tokens.
- Protected Routes: Restrict access to certain routes based on authentication status.
- Password Hashing: Secure user passwords with bcrypt.
To get a local copy up and running, follow these simple steps.
Ensure you have the following installed:
- Node.js
- MongoDB
- npm (Node Package Manager) or yarn
-
Clone the repository:
git clone https://github.com/your-username/User-Authentication-in-MERN-Stack.git
-
Navigate to the project directory:
cd User-Authentication-in-MERN-Stack
-
Install server-side dependencies:
cd server npm install
-
Install client-side dependencies:
cd ../client npm install
-
Start MongoDB server:
mongod
-
Start the backend server:
cd server npm start
-
Start the frontend server:
cd ../client npm start
-
Open your browser and navigate to
http://localhost:3000
.
User-Authentication-in-MERN-Stack/
├── client/ # React frontend
│ ├── public/ # Public assets
│ └── src/ # Source files
│ ├── components/ # React components
│ ├── pages/ # React pages
│ ├── services/ # API services
│ └── App.js # Main React component
├── server/ # Express backend
│ ├── config/ # Configuration files
│ ├── controllers/ # Route controllers
│ ├── models/ # Mongoose models
│ ├── routes/ # Express routes
│ └── server.js # Entry point
└── README.md # This file