Adding authentication and authorization to our web application
In this section, we will add authentication and authorization to our web application. We will use the jsonwebtoken library to implement the authentication part and will use a custom middleware to implement the authorization part.
Clone the base project
The authentication and authorization additions are not very complex, but it is quite long to follow with ease, so for this chapter you can download the project from https://github.com/PacktPublishing/NodeJS-for-Beginners/archive/refs/heads/main.zip and access the step4
folder. The implementation is ready to go, but I will comment on the most relevant changes that we made since the last chapter (step3
folder) so you can easily follow what we’ve done.
Setup
Our first steps are to explore the folder, install the dependencies, configure the environment, and start the infrastructure. This can be performed by running the following commands:
- Install the...