Created
July 18, 2018 07:26
-
-
Save brachi-wernick/22194dec8dae0e3d257339fc7edb3b06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { | |
if (route.component && route.data) { | |
let permissions = route.component[ACTIVATE_FIELD_NAME] as ActivateMetadata; | |
if (permissions) { | |
return this.securityService.userHasPermissions(permissions) | |
.map(hasAccess => { | |
if (hasAccess) { | |
return true; | |
} | |
else { | |
this.router.navigate(['/unauthorized'], {replaceUrl: true}) | |
} | |
}) | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment