1 import { Injectable } from '@angular/core'
3 ActivatedRouteSnapshot,
8 } from '@angular/router'
10 import { AuthService } from '../auth'
13 export class UserRightGuard implements CanActivate, CanActivateChild {
16 private router: Router,
17 private auth: AuthService
20 canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
21 const user = this.auth.getUser()
23 const neededUserRight = route.data.userRight
25 if (user.hasRight(neededUserRight)) return true
28 this.router.navigate([ '/login' ])
32 canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
33 return this.canActivate(route, state)