fix(auth): Aktualisierung der Authentifizierungsstatusbehandlung

- Methode `logInOut` aktualisiert, um nach dem Logout zu `/login` zu navigieren.
- Methoden `login` und `logout` angepasst, um `#IsAuthenticated` basierend auf der Antwort zu aktualisieren.
- Sicherstellung, dass der Authentifizierungsstatus nach Login und Logout korrekt gesetzt wird.
This commit is contained in:
Developer 02 2024-08-29 15:46:20 +02:00
parent 93417d1b37
commit 145d139e3a
2 changed files with 13 additions and 3 deletions

View File

@ -25,7 +25,7 @@ export class NavbarComponent {
async logInOut(): Promise<void> {
if (this.isLogedIn())
return this.authService.logoutAsync().then(() => {
this.router.navigate(['/']);
this.router.navigate(['/login']);
})
else
this.router.navigate(['/login']);

View File

@ -15,11 +15,21 @@ export class AuthService {
}
login(credentials: { username: string; password: string }): Observable<any> {
return this.http.post(`${this.url}/login`, credentials);
return this.http.post(`${this.url}/login`, credentials).pipe(
tap({
next: res => this.#IsAuthenticated = true,
error: () => this.#IsAuthenticated = false
})
)
}
logout(): Observable<any> {
return this.http.post(`${this.url}/logout`, {});
return this.http.post(`${this.url}/logout`, {}).pipe(
tap({
next: res => this.#IsAuthenticated = false,
error: () => this.#IsAuthenticated = true
})
);
}
async logoutAsync(): Promise<void> {