From the course: Angular: API Communication and Authentication

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

User login and generating JWTs

User login and generating JWTs

- [Instructor] Now that we have refactored our code, we are now ready to add in an authenticate route, that will issue a JSON web token, when the user provides the right credentials. We will be using the JSON Web Token library, which is a JSON Web Token implementation for node. This library will be used to sign the payload with a secret. You can generate a secret using the GRC Ultra High Security Password Generator. Every time you visit this page, a new password is generated for you. Grab the alphanumeric value, copy that, then head over to your .env file and paste that in as a value for JWT underscore secret. Let's head over to our api-router.js file. The JSON Web Token library should have already been installed when you ran npm install. That's required in this package. The const jwt require jsonwebtoken. We will also need bcrypt, the library that we use to hash the password. We'll be using to compare the hashed password against the user input. We'll declare a new post route at the…

Contents