/JWT-Authentication

basic implementation of JsonWebToken Authentication on node.js/express.js

Primary LanguageJavaScript

JWT-Authentication

This is a NodeJS app that implements a basic username and password authentication with JWT

Available APIs

User APIs:

POST /auth/register || /auth/login

You can do a POST to /auth/register to create a new user.

The body must have:

  • username: The username
  • password: The password
  • confirm-password: The password confirmation

You can do a POST to /auth/login to log a user in.

The body must have:

  • username: The username
  • password: The password

GET /posts || /users: for testing purpose

You can do a GET /posts to get all posts.

The headers must have:

  • Authorization: bearer user_token

You can do a GET /users to get all users.

The headers must have:

  • Authorization: bearer user_token

Prerequisites

You must install node.js in your machine

Running it

Clone the repository, run npm install and then run the server:

  • on development mode :

    npm run dev

  • on production mode :

    npm run start

You can change the PORT or the ACCESS_TOKEN_SECRET on /config/.env

Running the tests

Use REST Client extension

if you are using vs code install REST Client extension and try to use the Api endpoints in

/requests.rest file


Use Postman

The Collaboration Platform for API Development, it provides a powerful GUI platform to make your API development faster & easier

Authors