Created
July 18, 2018 07:10
-
-
Save brachi-wernick/3196e8fc31d291d15db2bdf61db6bde9 to your computer and use it in GitHub Desktop.
can activate guard base on route data
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.data.permissions; | |
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