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:
parent
93417d1b37
commit
145d139e3a
@ -25,7 +25,7 @@ export class NavbarComponent {
|
|||||||
async logInOut(): Promise<void> {
|
async logInOut(): Promise<void> {
|
||||||
if (this.isLogedIn())
|
if (this.isLogedIn())
|
||||||
return this.authService.logoutAsync().then(() => {
|
return this.authService.logoutAsync().then(() => {
|
||||||
this.router.navigate(['/']);
|
this.router.navigate(['/login']);
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
|
|||||||
@ -15,11 +15,21 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login(credentials: { username: string; password: string }): Observable<any> {
|
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> {
|
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> {
|
async logoutAsync(): Promise<void> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user