import { Injectable } from '@angular/core' ; import { Router , CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot } from '@angular/router' ; import { Logger } from '@shared' ; import { CredentialsService } from './credentials.service' ; const log = new Logger ( 'AuthenticationGuard' ) ; @ Injectable ( { providedIn : 'root' } ) export class AuthenticationGuard implements CanActivate { constructor ( private router , private credentialsService ) { } canActivate ( route , state ) { if ( this . credentialsService . isAuthenticated ( ) ) { return true ; } log . debug ( 'Not authenticated, redirecting and adding redirect url...' ) ; this . router . navigate ( [ '/login' ] , { queryParams : { redirect : state . url } , replaceUrl : true } ) ; return false ; } }