diff --git a/src/app/core/auth/auth.guard.spec.ts b/src/app/core/auth/auth.guard.spec.ts index a17e9141..9959c0ac 100644 --- a/src/app/core/auth/auth.guard.spec.ts +++ b/src/app/core/auth/auth.guard.spec.ts @@ -1,6 +1,6 @@ import { signal } from '@angular/core'; import { TestBed } from '@angular/core/testing'; -import { ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { ActivatedRouteSnapshot, RedirectCommand, RouterStateSnapshot } from '@angular/router'; import { of } from 'rxjs'; @@ -60,8 +60,8 @@ describe('AuthGuard', () => { TestBed.runInInjectionContext(() => { authGuard()(route, {} as RouterStateSnapshot).subscribe((result) => { - expect(result instanceof UrlTree).toBe(true); - expect(result.toString()).toBe('/signin'); + expect(result instanceof RedirectCommand).toBe(true); + expect((result as RedirectCommand).redirectTo.toString()).toBe('/signin'); done(); }); }); @@ -79,8 +79,8 @@ describe('AuthGuard', () => { TestBed.runInInjectionContext(() => { authGuard()(route, {} as RouterStateSnapshot).subscribe((result) => { - expect(result instanceof UrlTree).toBe(true); - expect(result.toString()).toBe('/unauthorized'); + expect(result instanceof RedirectCommand).toBe(true); + expect((result as RedirectCommand).redirectTo.toString()).toBe('/unauthorized'); done(); }); }); @@ -120,8 +120,8 @@ describe('AuthGuard', () => { TestBed.runInInjectionContext(() => { authGuard()(route, {} as RouterStateSnapshot).subscribe((result) => { - expect(result instanceof UrlTree).toBe(true); - expect(result.toString()).toBe('/unauthorized'); + expect(result instanceof RedirectCommand).toBe(true); + expect((result as RedirectCommand).redirectTo.toString()).toBe('/unauthorized'); done(); }); }); @@ -142,8 +142,8 @@ describe('AuthGuard', () => { TestBed.runInInjectionContext(() => { authGuard()(route, {} as RouterStateSnapshot).subscribe((result) => { - expect(result instanceof UrlTree).toBe(true); - expect(result.toString()).toBe('/unauthorized'); + expect(result instanceof RedirectCommand).toBe(true); + expect((result as RedirectCommand).redirectTo.toString()).toBe('/unauthorized'); done(); }); }); @@ -207,8 +207,8 @@ describe('AuthGuard', () => { TestBed.runInInjectionContext(() => { authGuard()(route, {} as RouterStateSnapshot).subscribe((result) => { - expect(result instanceof UrlTree).toBe(true); - expect(result.toString()).toBe('/eua'); + expect(result instanceof RedirectCommand).toBe(true); + expect((result as RedirectCommand).redirectTo.toString()).toBe('/eua'); done(); }); }); diff --git a/src/app/core/auth/auth.guard.ts b/src/app/core/auth/auth.guard.ts index 0689e827..08309120 100644 --- a/src/app/core/auth/auth.guard.ts +++ b/src/app/core/auth/auth.guard.ts @@ -1,5 +1,11 @@ import { inject } from '@angular/core'; -import { ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { + ActivatedRouteSnapshot, + GuardResult, + RedirectCommand, + Router, + RouterStateSnapshot +} from '@angular/router'; import { of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; @@ -58,18 +64,18 @@ export function authGuard(configOrRoles?: string | string[] | Partial sessionService.getCurrentEua()), - map((): boolean | UrlTree => { + map((): GuardResult => { // The user still isn't authenticated if (!session().isAuthenticated()) { - return router.parseUrl('/signin'); + return new RedirectCommand(router.parseUrl('/signin')); } // Check to see if the user needs to agree to the end user agreement if (config.requiresEua && !session().isEuaCurrent()) { - return router.parseUrl('/eua'); + return new RedirectCommand(router.parseUrl('/eua')); } - if (!session().isAdmin()) { + if (!session().isAdmin() || true) { // ----------------------------------------------------------- // Check the role requirements for the route // ----------------------------------------------------------- @@ -78,7 +84,7 @@ export function authGuard(configOrRoles?: string | string[] | Partial