The authentication was implemented to the backend using JWT. In Chapter 4, Securing and Testing Your Backend, we created JWT authentication, and the /login endpoint is allowed to everyone without authentication. In the frontend's login page we have to first call /login endpoint to get the token. After that, the token will be included to all requests we are sending to the backend, as was demonstrated in Chapter 4, Securing and Testing Your Backend.
Let's first create a login component that asks for credentials from the user to get a token from the backend:
- Create a new file, called Login.js, in the components folder. Now, your file structure of the frontend should be the following:
- Open the file in the VS Code editor ...