fix: auth guard

This commit is contained in:
eneller
2026-06-26 11:50:15 +02:00
parent 38dedfc829
commit 37fdc28e1f
7 changed files with 34 additions and 5 deletions

View File

@@ -16,7 +16,12 @@ export class APIService {
constructor(private http: HttpClient){}
login(username: string, password: string): Observable<any>{
return this.http.post(`${this.apiUrl}/auth/login`,{ 'username': username, 'password': password});
return this.http.post(`${this.apiUrl}/auth/login`,{ 'username': username, 'password': password}).pipe(
tap({
next: () => this.isAuthenticatedSubject.next(true),
error: () => this.isAuthenticatedSubject.next(false)
})
);
}
logout(): Observable<any>{
return this.http.post(`${this.apiUrl}/auth/logout`, {});

View File

@@ -7,8 +7,7 @@ export const authGuard: CanActivateFn = (route, state) => {
const api = inject(APIService);
const router = inject(Router);
//FIXME always redirected to login after page load
return api.isAuthenticated$.pipe(
return api.checkAuthStatus().pipe(
map((isAuthenticated) => {
if (isAuthenticated) {
return true;