diff --git a/projects/nshmp-apps/src/app/internal/shared/guards/network.guard.ts b/projects/nshmp-apps/src/shared/guards/network.guard.ts similarity index 100% rename from projects/nshmp-apps/src/app/internal/shared/guards/network.guard.ts rename to projects/nshmp-apps/src/shared/guards/network.guard.ts diff --git a/projects/nshmp-apps/src/app/internal/shared/services/auth.service.ts b/projects/nshmp-apps/src/shared/services/auth.service.ts similarity index 59% rename from projects/nshmp-apps/src/app/internal/shared/services/auth.service.ts rename to projects/nshmp-apps/src/shared/services/auth.service.ts index 7a39e67e440a27ef765a5e543ce01d954a1a864e..4ad61d7f018f54060471d561da56a0a2a0ccc425 100644 --- a/projects/nshmp-apps/src/app/internal/shared/services/auth.service.ts +++ b/projects/nshmp-apps/src/shared/services/auth.service.ts @@ -1,8 +1,13 @@ import {HttpClient} from '@angular/common/http'; import {Injectable} from '@angular/core'; -import {NshmpService, SpinnerService} from '@ghsc/nshmp-lib-ng/nshmp'; +import {MatDialogRef} from '@angular/material/dialog'; +import { + NshmpLibNgSpinnerComponent, + NshmpService, + SpinnerService, +} from '@ghsc/nshmp-lib-ng/nshmp'; import {environment} from 'projects/nshmp-apps/src/environments/environment'; -import {catchError, map} from 'rxjs'; +import {catchError, map, Observable} from 'rxjs'; interface AuthResponse { isAuthorized: boolean; @@ -24,14 +29,23 @@ export class AuthService { private nshmpService: NshmpService, ) {} - isAuthorized() { - const ref = this.spinnerService.show('Checking USGS network ...'); + /** + * Check if user is on USGS network for internal applications. + * + * @param required Whether the user must be on the network + */ + isAuthorized(required = true): Observable<boolean> { + let ref: MatDialogRef<NshmpLibNgSpinnerComponent> | undefined = undefined; + + if (required) { + ref = this.spinnerService.show('Checking USGS network ...'); + } return this.http.get<AuthResponse>(this.url).pipe( map(response => { - ref.close(); + ref?.close(); - if (!response.isAuthorized) { + if (!response.isAuthorized && required) { this.nshmpService.throwError$( new Error( 'Must be on USGS network to access internal applications', @@ -42,7 +56,7 @@ export class AuthService { return response.isAuthorized; }), catchError((error: Error) => { - ref.close(); + ref?.close(); return this.nshmpService.throwError$(error); }), );