fixed log4j issue
[eliot.git] / blueprints / common / eliot-ui / frontend-src / src / app / _services / AuthGuard.ts
1 import { Injectable } from '@angular/core';
2 import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
3
4 import { AuthenticationService } from './../_services/authentication.service';
5
6 @Injectable({ providedIn: 'root' })
7
8 export class AuthGuard implements CanActivate {
9   
10     constructor(
11         private router: Router,
12         private authenticationService: AuthenticationService
13     ) { }
14
15     canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
16         const currentUser = this.authenticationService.currentUserValue;
17         
18         console.log("current user");
19         console.log(currentUser);
20         
21         if (currentUser) {
22             // authorised so return true
23             return true;
24         }
25
26         // not logged in so redirect to login page
27         this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
28         return false;
29     }
30
31 }