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
From the course: Building Angular and ASP.NET Web API Apps
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…
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.
Contents
-
-
-
-
-
-
-
-
-
Setting up AuthController5m 10s
-
Setting up AuthService3m 8s
-
Creating a register component5m 6s
-
Registering users6m 18s
-
Generating a token6m 53s
-
Requesting a token from Angular4m 42s
-
Authentication check via tokens5m 11s
-
Logging out users1m 54s
-
Creating an Angular login component4m 47s
-
Getting data from the login form4m 25s
-
Logging in users4m 20s
-
Handling errors in angular4m 2s
-
-
-