X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fservices%2FAuthGuardService.ts;h=512705fa2dde000386a8f47117c0c9ceb86a61f6;hb=382448fed3f9d4d4cf9ac614e1275208d18b752f;hp=0c8d1e467358231c3fb9c2d9a92556571132ac29;hpb=3b4814aa2d3dec621dadb52f058ba95a3dc3a86a;p=osm%2FNG-UI.git diff --git a/src/services/AuthGuardService.ts b/src/services/AuthGuardService.ts index 0c8d1e4..512705f 100644 --- a/src/services/AuthGuardService.ts +++ b/src/services/AuthGuardService.ts @@ -22,8 +22,8 @@ import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; import { AuthenticationService } from 'AuthenticationService'; -import { Observable } from 'rxjs'; -import { map, take } from 'rxjs/operators'; +import { combineLatest, Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; /** * An Injectable is a class adorned with the @Injectable decorator function. @@ -45,17 +45,22 @@ export class AuthGuardService implements CanActivate { * Returns Observable if authorized @public */ public canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return this.authService.isLoggedIn - .pipe( - take(1), - map((isLoggedIn: boolean) => { - if (!isLoggedIn) { - this.router.navigate(['/login']).catch(() => { - //TODO: Handle error notification - }); - } + // eslint-disable-next-line deprecation/deprecation + return combineLatest( + this.authService.isLoggedIn, + this.authService.isChangePassword + ).pipe( + map(([isLoggedIn, changePassword]: [boolean, boolean]): boolean => { + if (changePassword || isLoggedIn) { return true; - }) - ); + } else { + this.router.navigate(['/login']).catch((): void => { + // Catch Navigation Error + }); + this.authService.destoryToken(); + return false; + } + }) + ); } }