25 lines
882 B
TypeScript
25 lines
882 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
|
|
|
import { AuthenticationService } from '@app/_services';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class AuthGuard implements CanActivate {
|
|
constructor(private router: Router, private authenticationService: AuthenticationService) {
|
|
}
|
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
|
const oauthToken = this.authenticationService.oauthTokenValue;
|
|
if (oauthToken) {
|
|
// logged in so return true
|
|
return true;
|
|
}
|
|
|
|
// not logged in so redirect to login page with the return url
|
|
this.authenticationService.popup('login');
|
|
|
|
//this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
|
|
return false;
|
|
}
|
|
}
|