Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot} from "@angular/router";
- import {AuthService} from "./auth.service";
- import {Injectable} from "@angular/core";
- @Injectable()
- export class AuthorizationGuard implements CanActivate {
- private allowedRoles:string[];
- constructor(private authService:AuthService) {
- }
- canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
- this.allowedRoles = route.data["roles"];
- const allowed:boolean = this.authService.currentUser.roles.filter(
- role=>this.allowedRoles.includes(role)).length > 0;
- return allowed;
- }
- }
Add Comment
Please, Sign In to add comment