Log out

Now that we're caching the login status, we need to implement a log out experience:

  1. In AuthService, implement a logout function:
src/app/auth/auth.service.ts...  logout() {    this.clearToken()    this.authStatus.next(defaultAuthStatus)  }
  1. Implement the logout component:
src/app/user/logout/logout.component.tsimport { Component, OnInit } from '@angular/core'import { Router } from '@angular/router'import { AuthService } from '../../auth/auth.service'@Component({  selector: 'app-logout',  template: `    <p>      Logging out...    </p>  `,  styles: [],})export class LogoutComponent implements OnInit {  constructor(private router: Router, private authService: AuthService) {}  ngOnInit() {    this.authService.logout()    this.router.navigate(['/'])  }}

As you note, ...

Get Angular 6 for Enterprise-Ready Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.