1
|
|
2
|
import {Injectable} from '@angular/core';
|
3
|
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
4
|
import {AuthenticationService} from './authentication.service';
|
5
|
import { getCookie } from '../domain/utils';
|
6
|
import { loginUrl } from "../domain/tempAPI";
|
7
|
|
8
|
@Injectable ()
|
9
|
export class AuthGuardService implements CanActivate {
|
10
|
|
11
|
// private oidc_endpoint : string = process.env.OIDC_ENDPOINT;
|
12
|
private loginUrl : string = loginUrl;
|
13
|
|
14
|
|
15
|
constructor(private authenticationService: AuthenticationService, private router: Router) {}
|
16
|
|
17
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
18
|
|
19
|
if (this.authenticationService.getIsUserLoggedIn()) { return true; }
|
20
|
|
21
|
if (getCookie('currentUser') != null) {return true;}
|
22
|
|
23
|
// Store the attempted URL for redirecting
|
24
|
sessionStorage.setItem("state.location",state.url);
|
25
|
// Navigate to the login page
|
26
|
window.location.href = this.loginUrl;
|
27
|
|
28
|
return false;
|
29
|
}
|
30
|
}
|