Skip to content
Snippets Groups Projects
Commit 320ccef2 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

move

parent b41fa49a
Branches
Tags
1 merge request!573Navigation Service
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core'; 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 {environment} from 'projects/nshmp-apps/src/environments/environment';
import {catchError, map} from 'rxjs'; import {catchError, map, Observable} from 'rxjs';
interface AuthResponse { interface AuthResponse {
isAuthorized: boolean; isAuthorized: boolean;
...@@ -24,14 +29,23 @@ export class AuthService { ...@@ -24,14 +29,23 @@ export class AuthService {
private nshmpService: NshmpService, 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( return this.http.get<AuthResponse>(this.url).pipe(
map(response => { map(response => {
ref.close(); ref?.close();
if (!response.isAuthorized) { if (!response.isAuthorized && required) {
this.nshmpService.throwError$( this.nshmpService.throwError$(
new Error( new Error(
'Must be on USGS network to access internal applications', 'Must be on USGS network to access internal applications',
...@@ -42,7 +56,7 @@ export class AuthService { ...@@ -42,7 +56,7 @@ export class AuthService {
return response.isAuthorized; return response.isAuthorized;
}), }),
catchError((error: Error) => { catchError((error: Error) => {
ref.close(); ref?.close();
return this.nshmpService.throwError$(error); return this.nshmpService.throwError$(error);
}), }),
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment