Implementing token authentication
After learning why JWT make sense, how tokens look and work, and how to use JWT to authenticate users, we will manually implement token authentication in our Redux application.
The backend server code is provided by this book. You can find the template code for this chapter in chapter7_1.zip
 (this contains the server and our React/Redux application from the previous chapters).
Unpack the zip file, change into the directory, and run npm install
 to install the dependencies.
For the sake of simplicity, the JWT tokens that the server generates do not expire, and the secret is set to secret
(so that we can use the debugger on jwt.io to generate valid tokens for testing purposes).
Note
You can change the secret by setting the JWT_SECRET
environment variable when starting the server.
Backend API
Before we start implementing authentication in our application, we will take a look at the changes in the backend API.
POST /api/login
The POST /api/login
API is new. Log in as...