import { Injectable } from '@angular/core'; import { Router, CanActivate } from '@angular/router'; import { ToastrService } from 'ngx-toastr'; import { AuthenticationService } from '../services/authentication.service'; @Injectable({ providedIn: 'root', }) export class AuthAdminGuardService implements CanActivate { constructor(private _router: Router, private toastr: ToastrService, private auth: AuthenticationService) { } async canActivate(): Promise { if (this.auth.userValue && this.auth.userValue.token) { const payload = this.auth.userValue.token.split('.')[1]; const ssoInfo = JSON.parse(atob(payload)); const adminRoleInfo = await this.auth.isAdmin(Number(ssoInfo.sso)); if (adminRoleInfo['data']) return true; } this._router.navigate(['home']); return false; } }