src/app/home/user-type.guard.ts
Properties |
|
Methods |
|
constructor(sharedPreferences: SharedPreferences, router: Router, appGlobalService: AppGlobalService)
|
||||||||||||
Defined in src/app/home/user-type.guard.ts:8
|
||||||||||||
Parameters :
|
Async canActivate |
canActivate()
|
Defined in src/app/home/user-type.guard.ts:15
|
Returns :
Promise<boolean>
|
import { Inject, Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { PreferenceKey, RouterLinks } from '@app/app/app.constant';
import { AppGlobalService } from '@app/services/app-global-service.service';
import { ProfileType, SharedPreferences } from 'sunbird-sdk';
@Injectable()
export class UserTypeGuard implements CanActivate {
constructor(
@Inject('SHARED_PREFERENCES') private sharedPreferences: SharedPreferences,
private router: Router,
public appGlobalService: AppGlobalService,
) {
}
async canActivate(): Promise<boolean> {
const isAdminUser = (await this.sharedPreferences.getString(PreferenceKey.SELECTED_USER_TYPE).toPromise() === ProfileType.ADMIN);
if (isAdminUser && this.appGlobalService.isUserLoggedIn()) {
this.router.navigate([`/${RouterLinks.HOME_TAB}/admin`]);
} else {
this.router.navigate([`/${RouterLinks.HOME_TAB}/user`]);
}
return false;
}
}