Skip to content

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. The project also includes a fully automated CI/CD pipeline.

Notifications You must be signed in to change notification settings

Aanttrax/ms-auth

Repository files navigation

🛡️ Authentication Microservice

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.

🚀 Features

  • 🛡️ 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.

📂 Project Structure

├── 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

🛠️ Installation

  1. Clone the repository:
    git clone https://github.com/Aanttrax/ms-auth.git
    cd ms-auth
  2. Install dependencies:
    npm install
  3. 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=**********
  4. Start the development server:
    npm run dev

🔗 API Endpoints

  1. Alive

    • GET /alive
    • Response:
      {
       "success": true,
       "response": "Server online"
      }
  2. 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"
  3. User Login

    • POST /signin
    • Request Body:
      {
       "email": "[email protected]",
       "password": "prueba"
      }
    • Response:
      {
       "success": true,
       "response": "logged-in user"
      }
    • Headers:
      "auth-token": "*laksjflieuaksjdhfknclkasjhfeiuhakjfaeh;f;s"
  4. isAuthenticated

    • GET /isauthenticated
    • Response:
      {
       "success": true,
       "response": true || false
      }

🤝 Contributing

  1. Fork the repository.
  2. Create a new branch:
    git checkout -b feature-name
  3. Commit your changes:
    git commit -m "Add your message"
  4. Push to the branch:
    git push origin feature-name
  5. Create a pull request.

🌟 Acknowledgements

  • 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.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

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. The project also includes a fully automated CI/CD pipeline.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published