import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot , UrlTree , Router } from '@angular/router' ; import { ToastrService } from 'ngx-toastr' ; import { Observable } from 'rxjs' ; import { AuthService } from '../services/auth.service' ; @ Injectable ( { providedIn : 'root' } ) export class AdminGuard implements CanActivate { constructor ( private authService , private toastrService , private router ) { } canActivate ( route , state ) { return this . haveRole ( ) ; } async haveRole ( ) { if ( await this . authService . haveRole ( "admin" ) ) { return true ; } else { this . router . navigate ( [ "/" ] ) ; this . toastrService . error ( "Bu alana erişemezsiniz!" , "Yetersiz Yetki" ) ; return false ; } } }