A secure and scalable authentication microservice built with TypeScript, Express, and MongoDB. This project implements robust features such as user registration, login, token-based authentication with JWT, and password hashing using bcrypt.
- 🛡️ JWT-based Authentication: Secure access with access and refresh tokens.
- 🔒 Password Hashing: Uses bcrypt for secure password storage.
- 📦 RESTful API: Clean and reusable API endpoints.
- 🧩 Modular Code Structure: Clean and scalable architecture.
- 📄 Environment Variables: Configurable via
.env
file.
├── src
│ ├── controllers # API controllers
│ ├── database # API database
│ │ └── schemas # Mongoose schemas
│ ├── environment # environments dev and prod
│ ├── helpers # Helper functions
│ │ ├── mappers # mappers
│ │ └── utilities # utilities
│ ├── interfaces # interfaces and types
│ ├── middleware # middlewares
│ ├── routes # Express routes
│ ├── server # Server entry point
│ │ ├── app.ts # Express app setup
│ │ └── db.ts # Mongo configuration
│ └── index.ts # App configuration
├── .env # Environment variables
├── tsconfig.json # TypeScript configuration
├── package.json # Dependencies and scripts
└── README.md # Project documentation
- Clone the repository:
git clone https://github.com/Aanttrax/ms-auth.git cd ms-auth
- Install dependencies:
npm install
- Set up environment variables: Create a .env file in the root directory and add the following:
PORT=3100 HOST=0.0.0.0 MONGO_USER=***** MONGO_PWD=******** MONGO_HOST=******************* MONGO_DB_NAME=************ MONGO_OPTIONS=******************** TOKEN_SECRET=**********
- Start the development server:
npm run dev
-
Alive
- GET
/alive
- Response:
{ "success": true, "response": "Server online" }
- GET
-
User Registration
- POST
/signup
- Request Body:
{ "userName": "john_doe", "password": "prueba", "name": "john", "lastName": "Doe", "email": "[email protected]" }
- Response:
{ "success": true, "response": "user created" }
- Headers:
"auth-token": "*laksjflieuaksjdhfknclkasjhfeiuhakjfaeh;f;s"
- POST
-
User Login
- POST
/signin
- Request Body:
{ "email": "[email protected]", "password": "prueba" }
- Response:
{ "success": true, "response": "logged-in user" }
- Headers:
"auth-token": "*laksjflieuaksjdhfknclkasjhfeiuhakjfaeh;f;s"
- POST
-
isAuthenticated
- GET
/isauthenticated
- Response:
{ "success": true, "response": true || false }
- GET
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add your message"
- Push to the branch:
git push origin feature-name
- Create a pull request.
- Express.js - Web framework for Node.js.
- TypeScript - Typed JavaScript at any scale.
- MongoDB - Database for modern applications.
- Bcrypt - Password hashing library.
- Jsonwebtoken - JWT implementation for authentication.
This project is licensed under the MIT License. See the LICENSE file for details.