import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot , Router } from '@angular/router' ; import { OAuthService } from 'angular-oauth2-oidc' ; import { Store } from '@ngxs/store' ; import { Login } from './auth.actions' ; @ Injectable ( ) export class AuthGuard implements CanActivate { constructor ( private oauthService , private store ) { } async canActivate ( route , state ) { if ( this . oauthService . hasValidIdToken ( ) || this . oauthService . hasValidAccessToken ( ) ) { return true ; } else { if ( this . oauthService . hasValidIdToken ( ) || this . oauthService . hasValidAccessToken ( ) ) { return true ; } else { this . store . dispatch ( new Login ( { infoMsg : 'Please login to Enter' } ) ) ; return false ; } } } }