-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
auth.guard.ts
27 lines (24 loc) · 1.04 KB
/
auth.guard.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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';
// import { waitUntil } from '@ngx-starter-kit/utils';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private oauthService: OAuthService, private store: Store) {}
async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
if (this.oauthService.hasValidIdToken() || this.oauthService.hasValidAccessToken()) {
return true;
} else {
// await waitUntil(_ => (<any>window).loginTryed === true);
if (this.oauthService.hasValidIdToken() || this.oauthService.hasValidAccessToken()) {
return true;
} else {
this.store.dispatch(new Login({ infoMsg: 'Please login to Enter' }));
// TODO return router.parseUrl('/notauthorized');
return false;
}
}
}
}