Now that we're caching the login status, we need to implement a log out experience:
- In AuthService, implement a logout function:
src/app/auth/auth.service.ts... logout() { this.clearToken() this.authStatus.next(defaultAuthStatus) }
- 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, ...