UAuthX is a user authentication system built with Node.js and MongoDB. It provides a secure and efficient way to manage user authentication for web applications.
- User registration with email and password
- User login with email and password
- Token-based authentication using JWT (JSON Web Tokens)
- Password hashing for secure storage
- Centralized management of user authentication
- Scalable architecture
-
Clone the repository:
git clone https://github.com/yourusername/UAuthX.git
-
Install dependencies:
cd UAuthX npm install
-
Set up environment variables: Create a
.env
file in the root directory and define the following variables:PORT=5000 MONGO_URI=mongodb://localhost:27017/uauthx SECRET_KEY=your_secret_key
-
Build the application:
npm run build
-
Start the server:
npm start
-
Build the Docker image:
docker build -t uauthx .
-
Run the Docker container:
docker run -p 5000:5000 \ -e PORT=5000 \ -e MONGO_URI=mongodb://localhost:27017/uauthx \ -e SECRET_KEY=your_secret_key \ -d uauthx
-
Pull the Docker image:
docker pull yourdockerhubusername/uauthx:latest
-
Run the Docker container:
docker run -p 5000:5000 \ -e PORT=5000 \ -e MONGO_URI=mongodb://localhost:27017/uauthx \ -e SECRET_KEY=your_secret_key \ -d yourdockerhubusername/uauthx:latest
Send a POST request to /auth/sign-up
with the following JSON body:
{
"email": "[email protected]",
"password": "password123"
}
-
Success:
{ "isSuccess": true, "authToken": "your_jwt_token" }
-
Error:
{ "isSuccess": false, "error": "Error message" }
Send a POST request to /auth/sign-in
with the following JSON body:
{
"email": "[email protected]",
"password": "password123"
}
-
Success:
{ "isSuccess": true, "authToken": "your_jwt_token" }
-
Error:
{ "isSuccess": false, "error": "Error message" }
Send a GET request to /auth/verify-user
with the Authorization header containing the Bearer token:
GET /auth/verify-user HTTP/1.1
Host: localhost:5000
Authorization: Bearer your_jwt_token
-
Success:
{ "isSuccess": true, "userId": "user_id_string" }
-
Error:
{ "isSuccess": false, "error": "Error message" }
To access protected routes, include the JWT token in the Authorization header of your requests:
Authorization: Bearer your_jwt_token
- Express.js - Web framework for Node.js
- Mongoose - MongoDB object modeling tool
- JSON Web Token (JWT) - Token-based authentication library
- Bcrypt.js - Password hashing library
Contributions are welcome! Please follow the Contributing Guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to the developers of Express, Mongoose, JWT, and Bcrypt.js for their excellent libraries.