Guest User

Untitled

a guest
Feb 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import {ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot} from "@angular/router";
  2.  
  3. import {AuthService} from "./auth.service";
  4. import {Injectable} from "@angular/core";
  5.  
  6. @Injectable()
  7. export class AuthorizationGuard implements CanActivate {
  8.  
  9. private allowedRoles:string[];
  10.  
  11. constructor(private authService:AuthService) {
  12. }
  13.  
  14. canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
  15.  
  16. this.allowedRoles = route.data["roles"];
  17.  
  18. const allowed:boolean = this.authService.currentUser.roles.filter(
  19. role=>this.allowedRoles.includes(role)).length > 0;
  20.  
  21. return allowed;
  22. }
  23. }
Add Comment
Please, Sign In to add comment