From d79a75d34f8ef756e69b6fb2bc0f90760d3a8cea Mon Sep 17 00:00:00 2001 From: eneller Date: Sat, 11 Apr 2026 01:40:37 +0200 Subject: [PATCH] fix: auth guard --- client/src/app/app.ts | 4 ++-- client/src/app/services/auth-guard.ts | 6 +++--- package.json | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/app/app.ts b/client/src/app/app.ts index 1291ef7..a4e0ce6 100644 --- a/client/src/app/app.ts +++ b/client/src/app/app.ts @@ -20,15 +20,15 @@ export class App implements OnInit{ active = '/'; constructor( - private router: Router + private router: Router, ){} ngOnInit(): void { + // show correct active tab this.router.events .pipe(filter(event => event instanceof NavigationEnd)) .subscribe(() =>{ this.active = this.router.url; - console.log(this.active); }); } diff --git a/client/src/app/services/auth-guard.ts b/client/src/app/services/auth-guard.ts index e136b7d..bbfb47c 100644 --- a/client/src/app/services/auth-guard.ts +++ b/client/src/app/services/auth-guard.ts @@ -1,14 +1,14 @@ import { inject } from '@angular/core'; import { CanActivateFn, Router } from '@angular/router'; import { APIService } from './api'; -import { map } from 'rxjs/operators'; +import { first, map } from 'rxjs/operators'; 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( + first(), map((isAuthenticated) => { if (isAuthenticated) { return true; diff --git a/package.json b/package.json index bf335eb..67a593d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "test": "echo \"Error: no test specified\" && exit 1", "server": "npm run dev --workspace=server", "client": "npm start --prefix client", - "dev": "concurrently \"npm run server\" \"npm run client\"" + "dev": "concurrently \"npm run server\" \"npm run client\"", + "teardown": "npm run teardown --workspace=server" }, "workspaces": [ "client",