A robust user authentication system built using Node.js and Express.js. This system supports registration, login, logout, token refreshing, password changes, and profile updates. It utilizes JWT for secure authentication and Cloudinary for managing avatar uploads.
-
User Registration
- Register with full name, email, username, and password.
- Avatar upload using Cloudinary.
-
User Login
- Login with email or username and password.
- JWT-based access and refresh token generation.
-
Logout
- Clears refresh and access tokens.
-
Token Refresh
- Refreshes the access token using the refresh token.
-
Password Management
- Change the current password securely.
-
Profile Management
- Update full name, email, or avatar.
-
Avatar Resizing
- The system automatically resizes uploaded avatars to 256x256 pixels before uploading them to Cloudinary.
-
Email Confirmation
- The system automatically send confirmation emails through a specified email service.
-
Get Current User
- Fetch details of the authenticated user.
-
Get Current Profile
- Fetch profile of the authenticated user.
project-root/
├── uploads/
├── src/
│ ├── app.js
│ ├── constants.js
│ ├── index.js
│ ├── controllers/
│ │ ├── events.controller.js
│ │ ├── member.controller.js
│ │ ├── problem.controller.js
│ │ ├── user.controller.js
│ ├── db/
│ │ └── index.js
│ ├── middlewares/
│ │ ├── auth.middleware.js
│ │ ├── authorize.middleware.js
│ │ ├── error.middleware.js
│ │ └── multer.middleware.js
│ ├── models/
│ │ ├── events.model.js
│ │ ├── member.model.js
│ │ ├── user.model.js
│ │ └── visitor.model.js
│ ├── routes/
│ │ ├── events.routes.js
│ │ ├── member.routes.js
│ │ ├── problem.routes.js
│ │ ├── user.routes.js
│ │ └── visitor.routes.js
│ └── utils/
│ ├── ApiError.js
│ ├── ApiResponse.js
│ ├── asyncHandler.js
│ ├── cloudinary.js
│ ├── ConfirmationEmail.js
│ ├── GoogleConfig.js
│ ├── ResizeImage.js
│ ├── scraper.js
│ └── UploadExternalImage.js
-
Clone the repository:
git clone https://github.com/your-repository/user-authentication-system.git
-
Navigate to the project directory:
cd user-authentication-system -
Install dependencies:
npm install
-
Create a
.envfile in the root directory and configure the following variables:MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret REFRESH_TOKEN_SECRET=your_refresh_token_secret CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name CLOUDINARY_API_KEY=your_cloudinary_api_key CLOUDINARY_API_SECRET=your_cloudinary_api_secret POTD_URL=your_potd_api_endpoint PROBLEM_DETAILS_URL=your_problem_details_api_endpoint EMAIL=your_email_details EMAILPORT=your_email_port_details HOST=your_email_host_details PASS=your_email_password_details
-
Start the server in development mode:
npm run dev
- Description: Register a new user.
- Middleware:
multerMiddleware - Request Body:
{ "fullName": "John Doe", "email": "john.doe@example.com", "username": "johndoe", "password": "password123", "avatar": "test.jpg" } - File Upload:
avatar(image file)
- Description: Login a user.
- Request Body:
{ "email": "john.doe@example.com", "password": "password123" }
- Description: Logout a user.
- Middleware:
authMiddleware
- Description: Refresh access token using the refresh token.
- Request Body:
{ "refreshToken": "your_refresh_token" }
- Description: Change the current password.
- Middleware:
authMiddleware - Request Body:
{ "oldPassword": "old_password", "newPassword": "new_password", "confirmPassword": "new_password" }
- Description: Get details of the authenticated user.
- Middleware:
authMiddleware
- Description: Retrieve the current user's profile information (full name, email, username, avatar, mobile number).
- Middleware:
authMiddleware - Request Body:
{ "fullName": "Johnathan Doe", "avatar": "url_to_avatar_image", "email": "johnathan.doe@example.com", "username": "johnathandoe", "mobileNo": "+1234567890" }
- Description: Update account details (full name and email).
- Middleware:
authMiddleware - Request Body:
{ "fullName": "Johnathan Doe", "email": "johnathan.doe@example.com" }
- Description: Update the user's avatar.
- Middleware:
authMiddleware, multerMiddleware - File Upload:
avatar(image file) - Additional Functionality: The uploaded avatar image is resized to 256x256 pixels before being uploaded to Cloudinary.
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JWT
- File Upload: Cloudinary
- Utilities: Multer, AsyncHandler, Custom Error Handling, Image Resizing with Sharp, Confirmation mail using nodemailer
This project is licensed under the MIT License.
Feel free to contribute by submitting a pull request. For major changes, please open an issue first to discuss what you would like to change.
This project is a Node.js-based backend application designed to fetch the "Problem of the Day" from GeeksforGeeks using their public APIs. The project extracts and cleans up the data to provide the problem's name, difficulty, description, and a link to the original source.
- Fetches the Problem of the Day (POTD) using GeeksforGeeks API.
- Provides cleaned and user-friendly problem descriptions by removing unnecessary HTML elements.
- Exposes a REST API endpoint to serve the processed problem details.
- Error handling for seamless API requests.
Before you begin, ensure you have met the following requirements:
- Node.js and npm installed (>= 16.x).
- Postman or any other tool for API testing.
-
Clone the repository:
git clone <repository-url> cd <repository-folder>
-
Install dependencies:
npm install
-
Create a
.envfile in the root directory and configure the necessary environment variables:PORT=8000
-
Start the server:
npm run dev
src/
|-- controllers/
| |-- problem.controller.js # Logic to handle problem fetching and processing
|-- middlewares/
| |-- error.middleware.js # Centralized error handling middleware
|-- routes/
| |-- problem.routes.js # Route definitions for the Problem of the Day API
|-- utils/
| |-- scraper.js # Utility to fetch and clean problem details
|-- app.js # Express application setup
|-- index.js # Entry point of the application
|-- constants.js # Holds constants like API URLs
.env # Environment variables
GET /api/v1/problems/potd
Fetches the Problem of the Day details.
{
"problemId": 701297,
"problemName": "Strings Rotations of Each Other",
"difficulty": "Easy",
"problemDescription": "You are given two strings of equal lengths...",
"problemLink": "https://www.geeksforgeeks.org/problems/..."
}- Open Postman.
- Create a new
GETrequest. - Enter the URL:
http://localhost:8000/api/v1/problems/potd - Hit
Sendand verify the response.
- Node.js: JavaScript runtime.
- Express.js: Web framework for Node.js.
- Cheerio.js: Parses and cleans HTML content.
- Axios: HTTP client for API requests.
- Dotenv: Environment variable management.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Make your changes and commit them:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature-name
- Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
- GeeksforGeeks for providing the APIs.
- Community contributors for helping with improvements.