From the course: Building Angular and ASP.NET Web API Apps

Unlock the full course today

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

Logging out users

Logging out users

From the course: Building Angular and ASP.NET Web API Apps

Start my 1-month free trial

Logging out users

- [Instructor] We have learned how to create a new user and then sign them in. Now, let us see how we can log them out. So for that, let us go to the authentication service. In the authentication service file, I'm going to create a new method named lotout. And this method will not take any parameters, because it will simply delete the username and the token from our local storage. For that write localStorage.removeItem. So we want to remove the item with the key userName, and then let us remove the item with the key token_value. Save the changes, and go to your header.component.html file. In here, let us add an additional button. And since we are going to show this button only when the users are authenticated, let us copy the line six. Paste it here, change the text to Logout, and then when the user clicks this button, we want to execute the logout method from the authentication service. So auth.logout. And then, save the changes. Also we don't want to show the register button if the…

Contents