From a2b01587b15b0d84fa9e3799c80d712d95c8d172 Mon Sep 17 00:00:00 2001 From: nymkappa <1612910616@pm.me> Date: Sat, 10 Feb 2024 10:31:56 +0100 Subject: [PATCH] [auth] small refactor --- frontend/src/app/services/services-api.service.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/services/services-api.service.ts b/frontend/src/app/services/services-api.service.ts index 3bb459b92..f11b3460c 100644 --- a/frontend/src/app/services/services-api.service.ts +++ b/frontend/src/app/services/services-api.service.ts @@ -4,7 +4,7 @@ import { HttpClient, HttpParams } from '@angular/common/http'; import { StateService } from './state.service'; import { StorageService } from './storage.service'; import { MenuGroup } from '../interfaces/services.interface'; -import { Observable, of, ReplaySubject, tap, catchError, share } from 'rxjs'; +import { Observable, of, ReplaySubject, tap, catchError, share, filter, switchMap } from 'rxjs'; import { IBackendInfo } from '../interfaces/websocket.interface'; import { Acceleration, AccelerationHistoryParams } from '../interfaces/node-api.interface'; @@ -64,13 +64,10 @@ export class ServicesApiServices { } this.getUserInfo$().subscribe(); - this.router.events.subscribe((event) => { - if (event instanceof NavigationStart) { - if (this.currentAuth !== localStorage.getItem('auth')) { - this.getUserInfo$().subscribe(); - } - } - }); + this.router.events.pipe( + filter((event) => event instanceof NavigationStart && this.currentAuth !== localStorage.getItem('auth')), + switchMap(() => this.getUserInfo$()), + ).subscribe(); } /**