src/app/auth/helpers/admin.guard.ts
Methods |
constructor(router: Router, authService: AuthService)
|
|||||||||
|
Defined in src/app/auth/helpers/admin.guard.ts:10
|
|||||||||
|
Parameters :
|
| canActivate | |||||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
|
|||||||||
|
Defined in src/app/auth/helpers/admin.guard.ts:14
|
|||||||||
|
Parameters :
Returns :
Observable | Promise | boolean | UrlTree
|
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
import { Observable } from 'rxjs';
import {AuthService} from '@app/auth/services/auth.service';
@Injectable({
providedIn: 'root'
})
export class AdminGuard implements CanActivate {
constructor(private router: Router, private authService: AuthService) { }
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const isAdmin = this.authService.isAdmin;
if (isAdmin) {
return true;
}
this.router.navigate(['projects']);
return false;
}
}