Git Product home page Git Product logo

microservice's Introduction

JWT Authentication System with Public API Microservice

This project demonstrates a JWT (JSON Web Token) authentication system using Node.js, along with a public API microservice. The main service handles user authentication and authorization using JWT, while the public API microservice provides access to certain routes without requiring login credentials but authorized with an API key.

Features

  • User Authentication with JWT: Securely generate and validate JWT tokens for user authentication.
  • Candidate Management: Add and retrieve candidate information to/from the database.
  • Public API Microservice: Access certain endpoints using an API key instead of email and password.

Project Components

Main Service

  • Endpoints:
    • POST /api/register: Register a new user.
    • POST /api/login: Authenticate a user and generate a JWT token.
    • POST /api/protected: Access a protected route (requires valid JWT token).
    • POST /api/candidate: Add a candidate to the database (requires valid JWT token).
    • GET /api/candidate: Retrieve candidates for the authenticated user (requires valid JWT token).

Public API Microservice

  • Endpoints:
    • POST /api/public/profile: Retrieve the profile information of the user corresponding to the provided API key.
    • GET /api/public/candidate: Retrieve all candidates for the user corresponding to the provided API key.

Getting Started

Prerequisites

  • Node.js
  • npm
  • MongoDB Atlas account (or a local MongoDB instance)

Installation

  1. Clone the repository:

    git clone https://github.com/kushvahasumit/microservice.git
    
  2. Install dependencies for both the main service and the public API microservice:

    For main service & public api:

    cd loginmicro
    npm install 
    
    cd ../public-api
    npm install
    
  3. Set up environment variables: Create a .env file in both main-service and public-api directories. Add the following variables to each .env file:

    MONGO_URL=<your_mongodb_url>
    PORT=<port_number>
    SEC_JWT=<your_jwt_secret>
    
    

Running the Services

  1. Start the main service:

    cd loginmicro
    npm run dev
    
  2. Start the public API microservice:

    cd ../publicapi
    npm run dev

microservice's People

Contributors

kushvahasumit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.