From the course: Angular: API Communication and Authentication
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Logging out of the application - Angular Tutorial
From the course: Angular: API Communication and Authentication
Logging out of the application
- [Instructor] Now that the user is able to login, obtain a JSON web token, and successfully view the data, it's also a necessary feature to allow the user to log out. All that the logout functionality should entail is to delete the user token from local storage, and then redirect the user to the login page. Let's add a logout button the menu. Open up the HTML file for your menu component. Let's go ahead and move the add contact button to this container here. And we'll go ahead and add the logout button to the menu. This will be first in a div with classes of right and menu. And we'll have a button here, and also give this some styling. And this will contain the logout text. Now when this button is clicked, all we do is call the logout method on this component. That's it to the component file. We will need the auth service we've previously implemented here, and this is in the shared folder. We then inject this here, in the constructor, and add the logout method to this component. This…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.