X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fservices%2FAuthGuardService.ts;fp=src%2Fservices%2FAuthGuardService.ts;h=2effecaea321bc0e160053672230c5bbcfb84495;hb=a9816553feb848341a8c3214861d5479c3688578;hp=0c8d1e467358231c3fb9c2d9a92556571132ac29;hpb=92d376dbeb4976952e4e99d5e53194d42d37787a;p=osm%2FNG-UI.git diff --git a/src/services/AuthGuardService.ts b/src/services/AuthGuardService.ts index 0c8d1e4..2effeca 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,19 @@ 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 - }); - } + 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(); + this.authService.destoryToken(); + return false; + } + }) + ); } }