From the course: Angular: API Communication and Authentication

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Auth service for local JWT management

Auth service for local JWT management - Angular Tutorial

From the course: Angular: API Communication and Authentication

Start my 1-month free trial

Auth service for local JWT management

- [Instructor] We will now be adding a layer of protection, which will prevent access to routing a UI unless the user is logged in. To aid in this effort, we'll need to create an authentication service for local JWT management. It will expose functions to tell us whether the user is logged in and also to retrieve the token. Let's pop in our terminal here and generate a new service using the CLI. Again, all shared services should be placed in the shared folder. Let's call this auth. Looks like I missed a service keyword. ng generate service and place it in the shared folder. Great. Let's head over to the app folder and the shared folder. And we can see that the auth service is now generated. We must first go to our app module and make sure that it's included in the ng module. Import AuthService from shared auth.service and make sure it's in the provider's property. Let's now head over to the auth.service. This auth.service will have four methods. One to set the token, one to get the…

Contents