From the course: Node.js: Microservices

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Add JWT tokens to the user service

Add JWT tokens to the user service - Node.js Tutorial

From the course: Node.js: Microservices

Add JWT tokens to the user service

- [Instructor] In this video, we will now change our user service so that it returns a JWT token on authentication. For that, I open first my user service. So I head into workspace, microservices, and user service, and there, I open routes index js. You also see on the terminal that I have the user service also here open, and I will now quit nodemon with Control C. And then I will first install a module that gives us JSON web token. And for that I type NPM install dash S and it's JSON Web token. And now I can right away, again, enter NPM run dev and start the user service again. Then I will bring in now JWT that we just installed by adding const, JWT equals require, JSON web token. Now I head down to my authentication route, so it's down here in post users authenticate. And now all I will do is instead of returning the user, I will now create the token. So const token equals JWT, and it has a method to sign a object.…

Contents