| import { Injectable } from '@angular/core'; |
| import { CanActivate } from '@angular/router/src/utils/preactivation'; |
| import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; |
| |
| import { AuthenticationService } from './authentication.service'; |
| |
| @Injectable({ |
| providedIn: 'root' |
| }) |
| export class AuthGuard implements CanActivate { |
| path: ActivatedRouteSnapshot[]; |
| route: ActivatedRouteSnapshot; |
| |
| constructor(private authStateService: AuthenticationService) { } |
| |
| canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { |
| if (route.data.roles) { |
| // check if current user has any role the route requires |
| return this.authStateService.isUserInRole(route.data.roles); |
| } |
| return true; |
| } |
| } |