To create the login and register REST API, the first thing we’ll set up is the JSON Web Token, which will help us authorize users by using a bearer token created by the server when the client makes a request. The client sends the bearer token with its request to the REST API. The REST API will verify if the token signature matches the payload and header, which will help determine if the bearer token is valid. If the REST API confirms the bearer token is valid, it will grant the client’s request or deny the request.

Setting up the JSONWebToken

To set up the JSON Web Token, we need to create a new file called JSONWebToken.js in the utils folder of our Node.js application. We then proceed to type the code below inside our file:

Get hands-on with 1200+ tech skills courses.