import { Injectable } from "@angular/core" ; import { ActivatedRouteSnapshot , CanActivate } from "@angular/router" ; import { SessionService } from "../session/session-service/session.service" ; import { RouteData } from "../view/dynamic-routing/view-config.interface" ; @ Injectable ( ) export class UserRoleGuard implements CanActivate { constructor ( private sessionService ) { } canActivate ( route ) { const routeData = route . data ; const user = this . sessionService . getCurrentUser ( ) ; if ( routeData ?. permittedUserRoles ?. length > 0 ) { return routeData . permittedUserRoles . some ( ( role ) => user ?. roles . includes ( role ) ) ; } else { return true ; } } }