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