Skip to content

FaelN1/jwt

Repository files navigation

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.

About

- Repository for JWT authentication using MongoDB and Bcrypt in Node.js. Easy-to-use, customizable implementation to add secure authentication to your applications.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors