aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/+admin/admin-guard.service.ts
blob: 429dc032db78c9bf2febe5cdcd2b75fc3158af64 (plain) (tree)
1
2
3
4
5
6
7




                                          

              






                                                                  



                             

                                                                           



                                                 





                                                                                
import { Injectable } from '@angular/core'
import {
  ActivatedRouteSnapshot,
  CanActivateChild,
  RouterStateSnapshot,
  CanActivate,
  Router
} from '@angular/router'

import { AuthService } from '../core'

@Injectable()
export class AdminGuard implements CanActivate, CanActivateChild {

  constructor (
    private router: Router,
    private auth: AuthService
  ) {}

  canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    if (this.auth.isAdmin() === true) return true

    this.router.navigate([ '/login' ])
    return false
  }

  canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    return this.canActivate(route, state)
  }
}