1 import { Injectable } from '@angular/core';
2 import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
4 import { AuthenticationService } from './../_services/authentication.service';
6 @Injectable({ providedIn: 'root' })
8 export class AuthGuard implements CanActivate {
11 private router: Router,
12 private authenticationService: AuthenticationService
15 canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
16 const currentUser = this.authenticationService.currentUserValue;
18 console.log("current user");
19 console.log(currentUser);
22 // authorised so return true
26 // not logged in so redirect to login page
27 this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });