File

src/app/tabs/usertype-specific-tab.guard.ts

Index

Methods

Constructor

constructor(preferences: SharedPreferences, router: Router)
Parameters :
Name Type Optional
preferences SharedPreferences No
router Router No

Methods

Async canActivate
canActivate()
Returns : Promise<boolean | UrlTree>
import { Inject, Injectable } from '@angular/core';
import { UrlTree, Router, CanActivate } from '@angular/router';
import { PreferenceKey, RouterLinks } from '../app.constant';
import { ProfileType, SharedPreferences } from '@project-sunbird/sunbird-sdk';
​
​
@Injectable()
export class UserTypeSpecificTabGuard implements CanActivate {
  constructor(@Inject('SHARED_PREFERENCES') private preferences: SharedPreferences,
              private router: Router) {}

  async canActivate(): Promise<boolean | UrlTree> {
    const selectedUserType = await this.preferences.getString(PreferenceKey.SELECTED_USER_TYPE).toPromise();
    if (selectedUserType === ProfileType.ADMIN) {
        return this.router.createUrlTree([RouterLinks.HOME_TAB]);
    }
    return true;
  }
}

results matching ""

    No results matching ""