fix(auth): Verbesserung von isAuthenticated() durch Überprüfung des HTTP-Antwortstatus

Die isAuthenticated()-Methode wurde aktualisiert, um den Anmeldestatus anhand des HTTP-Antwortstatus zu bestimmen, anstatt sich nur auf den Antwortkörper zu verlassen. Außerdem wird sichergestellt, dass `_isLogedIn` im Fehlerfall explizit auf false gesetzt wird. Dies verbessert die Zuverlässigkeit der Sitzungsvalidierung.
This commit is contained in:
2025-07-22 15:45:38 +02:00
parent 55822047bc
commit f79fa4ca27
3 changed files with 41 additions and 50 deletions

View File

@@ -36,7 +36,7 @@ export class NavMenuComponent {
isChecked = true;
constructor(private dialog: MatDialog, private authService: AuthenticationService, public refreshService: RefreshService, public creationService: CreationService, public updateService: UpdateService, public transferService: TransferService, public buttonVisibilityService: ButtonVisibilityService, public deletionService: DeletionService) {
this.authService.isAuthenticated().then().catch()
this.authService.isAuthenticated()
this.updateActCount = this.updateService.totalCount;
this.updateService.addChangeListener(UpdateEvent.CountChange, () => {
this.updateActCount = updateService.totalCount;

View File

@@ -25,13 +25,14 @@ export class AuthenticationService {
async isAuthenticated(): Promise<boolean> {
try {
const response = await firstValueFrom(this.http.get<boolean>(this.checkUrl, { withCredentials: true }));
_isLogedIn = response;
return response;
const response = await firstValueFrom(this.http.get(this.checkUrl, { withCredentials: true, observe: 'response' }));
_isLogedIn = response?.status === 200;
return _isLogedIn;
} catch (error: any) {
if (error?.status !== 401)
this.showErrorAlert();
return false;
_isLogedIn = false
return _isLogedIn;
}
}
@@ -81,4 +82,4 @@ export class AuthenticationService {
}
let _isLogedIn: boolean = false;
export const IsLogedIn = () => _isLogedIn
export const IsLogedIn = () => _isLogedIn