This is a Back-End API for user authentication and account management, built with Node.js, Express.js, and MongoDB. It provides JWT-based authentication, user registration, login, and email verification capabilities.
- User registration with email verification
- User login with JWT authentication
- Password management and security
- MongoDB & Mongoose integration
- Nodemailer for email notifications
- Authentication middleware
- CORS support
- Environment-based configuration
express-mongodb-authentication-system/
├── controllers/ # Handles business logic
│ └── authController.js
│
├── middlewares/ # Middleware (auth, validation, etc.)
│ └── userAuth.js
│
├── models/ # Mongoose models (schemas)
│ └── userModel.js
│
├── routes/ # API routes
│ └── authRoutes.js
│
├── config/ # Configuration files
│ ├── mongodb.js # MongoDB connection
│ └── nodemailer.js # Email configuration
│
├── server.js # Express app entry point
├── package.json # Dependencies & scripts
└── .env # Environment variables (not included in repo)
-
Clone the repository
git clone https://github.com/AymaneMehdi/express-mongodb-authentication-system.git cd express-mongodb-authentication-system -
Install dependencies
npm install
-
Set up environment variables
Create a.envfile in the root directory:PORT=5000 MONGODB_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key EMAIL_USER=your_email@gmail.com EMAIL_PASSWORD=your_email_password
npm run serverThis will run the server at http://localhost:5000 with automatic restart on file changes.
node server.js- Node.js
- Express.js
- MongoDB + Mongoose
- JWT Authentication
- Nodemailer (for email notifications)
- dotenv (for environment management)
POST /api/auth/register- Register a new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userPOST /api/auth/send-verify-otp- Send OTP for email verification (requires authentication)POST /api/auth/verify-email- Verify email with OTP (requires authentication)POST /api/auth/is-auth- Check if user is authenticated (requires authentication)POST /api/auth/send-reset-otp- Send OTP for password resetPOST /api/auth/reset-password- Reset password with OTP
This project is licensed under the MIT License.
Author: Aymane Mehdi