Implementing JWT auth
In Chapter 8, Designing Authentication and Authorization, we discussed how to implement a JWT-based authentication mechanism. In LemonMart, you implemented a base auth service that can be extended for custom authentication services.
We'll leverage three packages for our implementation:
jsonwebtoken
: Used to create and encode JWTsbcryptjs
: Used to hash and salt a user's password before saving it in the database, so we never store a user's password in plain textuuid
: A generated universally unique identifier that is useful when resetting a user's password to a random value
A hash function is a consistently repeatable, one-way encryption method, which means you get the same output every time you provide the same input, but even if you have access to the hashed value, you cannot readily figure out what information it stores. We can, however, compare whether the user has entered the correct password...