Sahil-Sayyad / Authentication_System_Pixelwand

This API provides user registration, login, logout, and token refresh functionality for the Pixelwand application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authentication System API

This API provides user registration, login, logout, and token refresh functionality for the Pixelwand application.

Base URL: http://localhost:8000

Endpoints

  • 1. User Registration

    Endpoint: /register
    Method: POST
    Description: Allows users to create a new account by providing their email, password, and name.

    Request Body:
            {
              "email": "user@example.com",
              "password": "password123",
              "confirm_password":"password123",
              "username": "John Doe"
            }
  Response:
            {
              "token": "your-generated-jwt-token"
            }
  • 2. User Login

    Endpoint: /login
    Method: POST
    Description: Allows registered users to log in by providing their email and password.

    Request Body:

          {
            "email": "user@example.com",
            "password": "password123"
          }
  Response:
            {
              "token": "your-generated-jwt-token"
            }
  • 3. User Logout

    Endpoint: /logout
    Method: GET
    Description: Allows users to log out of a specific session, invalidating the provided session token.

    Request Headers:
    Authorization: Bearer your-jwt-token

    Response:

         {
           "message": "Logout successful"
         }
    
  • 4. Token Refresh

    Endpoint: /refresh
    Method: GET
    Description: Allows users to refresh their session token, extending their session's validity.

    Request Headers:
    Authorization: Bearer your-jwt-token

    Response:

         {
           "token": "your-newly-generated-jwt-token"
         }
    
  • 5. Protected Route

    Endpoint: /protected
    Method: GET
    Description: Allows only those authenticated users .

    Request Headers:
    Authorization: Bearer your-jwt-token

    Response:

         {
           "message": "This is a protected route"
         }
    

    Authentication Flow

    To use protected endpoints (/logout, /refresh, /protected),
    include the JWT token in the Authorization header as follows:
    Bearer your-jwt-token.
    For Unit and integration tests Use the npx jest command
    ScreenShot Unit Testing

    Screenshot (149)

    ScreenShot How To Add Bearer Token

    Screenshot (148)

Getting Started

To get started with the Pixelwand authentication system, follow these steps:

  • I.   Clone Git Repo
    ---- git clone https://github.com/Sahil-Sayyad/MongoDB_Authentication_System_Pixelwand.git

  • II.  Install NPM dependencies
    ---- npm install
  • III.  Set Up .env File
    ---- add monngoDb url
    1. Use Postman or Thunder Client for Testing API Endpoints.
    1. Register a new user by making a POST request to /register with the required user information.
    1. Log in by making a POST request to /login with your email and password.
    1. Use the generated JWT token in the Authorization header for protected endpoints (/logout, /refresh, /protected).
    1. To log out, make a GET request to /logout with the JWT token in the Authorization header.
    1. To refresh your token, make a GET request to /refresh with the JWT token in the Authorization header.
    1. To see protected route, make a GET request to /protected with the JWT token in the Authorization header.
    1. For Unit Testing Use the Jest Type Follwoing Command npx jest

About

This API provides user registration, login, logout, and token refresh functionality for the Pixelwand application.


Languages

Language:JavaScript 100.0%