import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot , UrlTree , Router } from '@angular/router' ; import { Observable } from 'rxjs' ; import { AuthService } from '../services/auth.service' ; @ Injectable ( { providedIn : 'root' } ) export class AuthGuard implements CanActivate { constructor ( private auth , private router ) { } canActivate ( next , state ) { const loggedIn = ! ! this . auth . isLoggedIn ( ) ; if ( ! loggedIn ) { this . router . navigate ( [ '/auth' ] ) ; return false ; } return true ; } }