From 31b140fe80484542ecb1af6933767fe1eabfbf6c Mon Sep 17 00:00:00 2001 From: FyloZ Date: Sat, 13 Mar 2021 13:22:07 -0500 Subject: [PATCH] =?UTF-8?q?L'utilisateur=20est=20maintenant=20d=C3=A9conne?= =?UTF-8?q?ct=C3=A9=20lorsque=20sa=20connexion=20est=20expir=C3=A9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/modules/accounts/services/account.service.ts | 4 +--- src/app/modules/shared/app-state.ts | 7 +++++++ src/app/modules/shared/service/api.service.ts | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/app/modules/accounts/services/account.service.ts b/src/app/modules/accounts/services/account.service.ts index 572d2ce..6d02458 100644 --- a/src/app/modules/accounts/services/account.service.ts +++ b/src/app/modules/accounts/services/account.service.ts @@ -73,9 +73,7 @@ export class AccountService implements OnDestroy { ) .subscribe({ next: () => { - this.appState.isAuthenticated = false - this.appState.authenticationExpiration = -1 - this.appState.authenticatedEmployee = null + this.appState.resetAuthenticatedEmployee() this.checkAuthenticationStatus() success() }, diff --git a/src/app/modules/shared/app-state.ts b/src/app/modules/shared/app-state.ts index 968559c..772bd25 100644 --- a/src/app/modules/shared/app-state.ts +++ b/src/app/modules/shared/app-state.ts @@ -13,6 +13,13 @@ export class AppState { authenticatedUser$ = new Subject<{ authenticated: boolean, authenticatedUser: Employee }>() serverOnline$ = new Subject() + resetAuthenticatedEmployee() { + this.isAuthenticated = false + this.authenticationExpiration = -1 + this.authenticatedEmployee = null + + } + set isServerOnline(isOnline: boolean) { if (!isOnline) this.authenticatedEmployee = null this.serverOnline$.next(isOnline); diff --git a/src/app/modules/shared/service/api.service.ts b/src/app/modules/shared/service/api.service.ts index 4d083d7..3deff1e 100644 --- a/src/app/modules/shared/service/api.service.ts +++ b/src/app/modules/shared/service/api.service.ts @@ -7,6 +7,7 @@ import {Router} from '@angular/router' import {map, share, takeUntil} from 'rxjs/operators' import {valueOr} from '../utils/utils' import {ErrorService} from './error.service' +import {AccountService} from '../../accounts/services/account.service' @Injectable({ providedIn: 'root' @@ -77,17 +78,16 @@ export class ApiService implements OnDestroy { console.error('httpOptions need to be specified to use credentials in HTTP methods.') } } else { + this.appState.resetAuthenticatedEmployee() this.navigateToLogin() } } - const result$ = requestOptions.takeFullResponse + return requestOptions.takeFullResponse ? requestFn(httpOptions) .pipe(takeUntil(this._destroy$), share()) : requestFn(httpOptions) .pipe(takeUntil(this._destroy$), map(r => r.body), share()) - - return result$ } private checkAuthenticated(): boolean {