diff --git a/apps/red-ui/src/app/guards/composite-route.guard.ts b/apps/red-ui/src/app/guards/composite-route.guard.ts index d64d9bbda..a275cc828 100644 --- a/apps/red-ui/src/app/guards/composite-route.guard.ts +++ b/apps/red-ui/src/app/guards/composite-route.guard.ts @@ -1,7 +1,6 @@ import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; import { Injectable, Injector } from '@angular/core'; -import { from, Observable, of } from 'rxjs'; -import { catchError, map, mergeMap, tap } from 'rxjs/operators'; +import { from, of } from 'rxjs'; import { AppLoadStateService } from '../services/app-load-state.service'; @Injectable({ @@ -10,9 +9,8 @@ import { AppLoadStateService } from '../services/app-load-state.service'; export class CompositeRouteGuard implements CanActivate { constructor(protected readonly _router: Router, protected readonly _injector: Injector, private readonly _appLoadStateService: AppLoadStateService) {} - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { + async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { this._appLoadStateService.pushLoadingEvent(true); - let compositeCanActivateObservable: Observable = of(true); const routeGuards = route.data.routeGuards; @@ -26,29 +24,17 @@ export class CompositeRouteGuard implements CanActivate { if (typeof canActivateResult === 'boolean' || canActivateResult instanceof UrlTree) { canActivateResult = of(canActivateResult); } - const canActivatePipe: Observable = canActivateResult.pipe(map((m) => !!m)); - compositeCanActivateObservable = compositeCanActivateObservable.pipe( - mergeMap((bool) => { - if (!bool) { - return of(false); - } else { - return canActivatePipe; - } - }) - ); + + const result = await canActivateResult.toPromise(); + if (!result) { + this._appLoadStateService.pushLoadingEvent(false); + return false; + } } } - compositeCanActivateObservable = compositeCanActivateObservable.pipe( - tap(() => { - this._appLoadStateService.pushLoadingEvent(false); - }), - catchError(() => { - this._appLoadStateService.pushLoadingEvent(false); - return of(false); - }) - ); + this._appLoadStateService.pushLoadingEvent(false); - return compositeCanActivateObservable; + return true; } } diff --git a/apps/red-ui/src/app/modules/auth/auth.guard.ts b/apps/red-ui/src/app/modules/auth/auth.guard.ts index ae189e618..e318231b3 100644 --- a/apps/red-ui/src/app/modules/auth/auth.guard.ts +++ b/apps/red-ui/src/app/modules/auth/auth.guard.ts @@ -27,6 +27,7 @@ export class AuthGuard extends KeycloakAuthGuard { idpHint: this._appConfigService.getConfig(AppConfigKey.OAUTH_IDP_HINT, null), redirectUri: window.location.origin + this._baseHref + state.url }); + return false; } await this._userService.loadCurrentUser();