import { Injectable } from '@angular/core' ; import { CanActivate , Router } from '@angular/router' ; import { AuthService } from './auth.service' ; @ Injectable ( { providedIn : 'root' } ) export class IsAuthenticated implements CanActivate { constructor ( private auth , private router ) { } async canActivate ( ) { if ( await this . auth . isAuthenticated ( ) ) { return true ; } this . router . navigate ( [ '/sign-in' ] ) ; return false ; } } @ Injectable ( { providedIn : 'root' } ) export class IsNotAuthenticated implements CanActivate { constructor ( private auth , private router ) { } async canActivate ( ) { if ( ! await this . auth . isAuthenticated ( ) ) { return true ; } this . router . navigate ( [ '/private' ] ) ; return false ; } }