Giter VIP home page Giter VIP logo

jwt's Introduction

JWT-AUTHENTICATION - NodeJs/TypeScript Authentication API

This project is a Node.js API developed in Typescript that provides JSON Web Token (JWT) authentication. The API enables user registration, login and access control to protected routes.

About the project

This is a Node.js API developed with Typescript that implements JWT authentication for user registration, login, and access control to protected routes. It also has routes for creating users and editing usernames that require authentication via JWT token. The API is designed to provide a secure and scalable solution for authenticating users in web applications. Its well-documented code can serve as a solid foundation for similar projects.

How to use

To run the API, just clone or download the repository and follow the steps below

API Register

Endpoint: /api/register

Method: POST

Description: Creates a new user account.

Request Body:

  • name (string, required): The user's name.
  • email (string, required): The user's email address.
  • password (string, required): The user's password.

Responses:

  • 201 Created: If the user is created successfully.
  • 400 Bad Request: If the name, email, or password fields are missing or empty.
  • 401 Bad Request: If the email is already in use.
  • 500 Internal Server Error: If an unexpected error occurs.

API Login

Endpoint: /api/login

Method: POST

Description: Authenticates a user and returns a JWT token.

Request Body:

  • email (string, required): The user's email address.
  • password (string, required): The user's password.

Responses:

  • 200 OK: If the email and password are correct, returns a token that is needed for authentication in all other requests. The token is sent as a bearer token.
  • 400 Unauthorized: If the user does not exist.
  • 401 Bad Request: If the email or password is incorrect.
  • 500 Internal Server Error: If an unexpected error occurs.

API Edit

Endpoint: /api/edit/:id

Method: PATCH

Description: Edit the name of an existing user.

Request Parameters:

  • id (string, required): The ID of the user to edit.

Request Body:

  • name (string, required): The new name of the user.

Request Headers:

  • Authorization (string, required): The JWT token received from the login endpoint. Sent as a bearer token.

Responses:

  • 400 Bad Request: If the user does not exist.
  • 2011 Created: If the user is edited successfully.
  • 500 Internal Server Error: If an unexpected error occurs.

Contact

Linkedin or WhatsApp.

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.