A full-stack authentication system built with the MEAN stack (MongoDB, Express.js, Angular, and Node.js) featuring JWT-based authentication, role management, and protected routes.
User Authentication
-
Registration with name, email, and password
-
Login with email and password
-
JWT-based session management
-
Password hashing with bcrypt
-
-
Protected Routes
-
Frontend route guards
-
Backend middleware protection
-
Role-based authorization (user/admin)
-
-
Modern UI
-
Angular Material components
-
Responsive design
-
Form validations
-
Success/error notifications
-
-
Technologies Used
-
Frontend: Angular 19+, Angular Material
-
Backend: Node.js, Express.js
-
Database: MongoDB (with Mongoose ODM)
-
Authentication: JSON Web Tokens (JWT)
-
Security: bcrypt password hashing
-
-
Prerequisites Before you begin, ensure you have met the following requirements:
-
Node.js (v22+ recommended)
-
Angular CLI (v19+)
-
MongoDB (local instance or cloud connection)
-
Git
-
- Clone the repository
git clone https://github.com/your-username/mean-auth-system.git
cd mean-auth-system- Set up the backend
cd backend
npm install- Configure environment variables
Create a
.envfile in thebackendfolder:
MONGO_URI=mongodb://localhost:27017/mean-auth
JWT_SECRET=your_very_secure_secret
JWT_EXPIRE=30d
PORT=5000
NODE_ENV=development- Set up the frontend
cd ../frontend
npm install- Start the backend server
cd backend
npm start- Start the Angular development server
cd ../frontend
ng serve- Access the application Open your browser and navigate to:
http://localhost:4200
mean-auth-system/
├── backend/ # Node.js/Express backend
│ ├── config/ # Database configuration
│ ├── middlewares/ # Authentication middleware
│ ├── models/ # Mongoose models
│ ├── routes/ # API routes
│ ├── .env # Environment variables
│ └── server.js # Express server entry point
│
├── frontend/ # Angular frontend
│ ├── src/
│ │ ├── app/
│ │ │ ├── components/ # Angular components
│ │ │ ├── guards/ # Route guards
│ │ │ ├── interceptors/# HTTP interceptors
│ │ │ ├── models/ # TypeScript interfaces
│ │ │ ├── services/ # Angular services
│ │ │ └── *.module.ts # Angular modules
│ │ └── assets/ # Static assets
│ └── angular.json # Angular configuration
│
├── LICENSE
└── README.md
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /api/auth/signup | Register a new user | Public |
| POST | /api/auth/login | Authenticate user and return JWT | Public |
| GET | /api/auth/welcome | Get welcome message for auth user | Private |
Contributions are welcome! Please follow these steps:
-
- Fork the project
-
- Create your feature branch (
git checkout -b feature/AmazingFeature)
- Create your feature branch (
-
- Commit your changes (
git commit -m 'Add some AmazingFeature')
- Commit your changes (
-
- Push to the branch (
git push origin feature/AmazingFeature)
- Push to the branch (
-
- Open a Pull Request
License This project is licensed under the MIT License - see the LICENSE file for details.
-
MEAN stack documentation
-
JWT.io for authentication standards
-
Angular Material for UI components