L'utilisateur est maintenant déconnecté lorsque sa connexion est expirée.

This commit is contained in:
FyloZ 2021-03-13 13:22:07 -05:00
parent caa82ff64e
commit 31b140fe80
3 changed files with 11 additions and 6 deletions

View File

@ -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()
},

View File

@ -13,6 +13,13 @@ export class AppState {
authenticatedUser$ = new Subject<{ authenticated: boolean, authenticatedUser: Employee }>()
serverOnline$ = new Subject<boolean>()
resetAuthenticatedEmployee() {
this.isAuthenticated = false
this.authenticationExpiration = -1
this.authenticatedEmployee = null
}
set isServerOnline(isOnline: boolean) {
if (!isOnline) this.authenticatedEmployee = null
this.serverOnline$.next(isOnline);

View File

@ -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 {