Skip to content

Latest commit

 

History

History
147 lines (126 loc) · 3.1 KB

File metadata and controls

147 lines (126 loc) · 3.1 KB

In-Memory Authentication API

This is a lightweight authentication API built using Node.js and Express. It supports user sign-up, sign-in, and profile retrieval with an in-memory storage approach.

Features

  • Sign Up: Register new users.
  • Sign In: Authenticate existing users and receive a JWT token.
  • Profile Management: Fetch user information using a valid token.
  • In-Memory Storage: No database required; all data is stored in-memory for simplicity.

Live Demo

Frontend

Installation

  1. Clone the repository:

    git clone https://github.com/Tridib11/Authentication-api.git
  2. Navigate to the project folder:

    cd Authentication-api
  3. Install dependencies:

    npm install
  4. Start the server:

    node index.js

    The server will run on http://localhost:3000.

API Endpoints

1. GET /

  • Description: Check if the server is running.
  • Response:
    {
      "msg": "Server is running"
    }

2. POST /signup

  • Description: Register a new user.
  • Request Body:
    {
      "username": "your_username",
      "password": "your_password"
    }
  • Response:
    {
      "msg": "You are signed in successfully"
    }
  • Error:
    {
      "msg": "User already exists"
    }

3. POST /signin

  • Description: Log in a user and receive a JWT token.
  • Request Body:
    {
      "username": "your_username",
      "password": "your_password"
    }
  • Response:
    {
      "token": "your_jwt_token"
    }
  • Error:
    {
      "msg": "Sorry user does not exist!"
    }

4. GET /me

  • Description: Fetch user information. Requires a valid JWT token.
  • Headers:
    {
      "token": "your_jwt_token"
    }
  • Response:
    {
      "username": "your_username",
      "password": "your_password"
    }
  • Error:
    {
      "msg": "User not found"
    }

Middleware

  • auth: Verifies the JWT token.
  • logger: Logs the incoming request method.

Tech Stack

  • Backend: Node.js, Express
  • Authentication: JWT (JSON Web Tokens)
  • CORS: Enabled for cross-origin requests
  • Frontend: Deployed on Netlify

How It Works

  1. Sign Up to create a new account.
  2. Sign In to receive a JWT token.
  3. Use the token to access the Profile Information endpoint.

Project Structure

.
├── index.js         # Main server file
├── package.json     # Project dependencies
└── README.md        # Documentation

License

This project is licensed under the MIT License. Feel free to use and modify it as needed.

Author

Tridib
GitHub