File

src/app/manage-learn/core/guards/ml.guard.ts

Index

Methods

Constructor

constructor(utils: UtilsService, toast: ToastService)
Parameters :
Name Type Optional
utils UtilsService No
toast ToastService No

Methods

canActivate
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot)
Parameters :
Name Type Optional
next ActivatedRouteSnapshot No
state RouterStateSnapshot No
Returns : Observable | Promise | boolean | UrlTree
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { ToastService, UtilsService } from '../services';

@Injectable({
  providedIn: 'root'
})
export class MlGuard implements CanActivate {
  constructor(private utils: UtilsService, private toast: ToastService) {

  }
  canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
    return new Promise((resolve, reject) => {
      if (this.utils.profile && this.utils.profile.userSubType) {
        resolve(true)
      } else {
        this.utils.getProfileData().then(data => {
          if (data.role) {
            resolve(true)
          } else {
            this.toast.showMessage("You do not have access. Please update your profile", 'danger');
            resolve(false);
          }
        }).catch(error => {
          this.toast.showMessage("You do not have access.Please update your profile", 'danger');
          resolve(false)
        })
      }
    })
  }

}

results matching ""

    No results matching ""