fix: auth guard

This commit is contained in:
eneller
2026-04-11 01:40:37 +02:00
parent 38dedfc829
commit d4241aaaa0
3 changed files with 8 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ import {
NgbNavLinkBase, NgbNavLinkBase,
} from '@ng-bootstrap/ng-bootstrap/nav'; } from '@ng-bootstrap/ng-bootstrap/nav';
import { filter } from 'rxjs'; import { filter } from 'rxjs';
import { APIService } from './services/api';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@@ -20,15 +21,15 @@ export class App implements OnInit{
active = '/'; active = '/';
constructor( constructor(
private router: Router private router: Router,
){} ){}
ngOnInit(): void { ngOnInit(): void {
// show correct active tab
this.router.events this.router.events
.pipe(filter(event => event instanceof NavigationEnd)) .pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() =>{ .subscribe(() =>{
this.active = this.router.url; this.active = this.router.url;
console.log(this.active);
}); });
} }

View File

@@ -1,14 +1,15 @@
import { inject } from '@angular/core'; import { inject } from '@angular/core';
import { CanActivateFn, Router } from '@angular/router'; import { CanActivateFn, Router } from '@angular/router';
import { APIService } from './api'; import { APIService } from './api';
import { map } from 'rxjs/operators'; import { first, map } from 'rxjs/operators';
export const authGuard: CanActivateFn = (route, state) => { export const authGuard: CanActivateFn = (route, state) => {
const api = inject(APIService); const api = inject(APIService);
const router = inject(Router); const router = inject(Router);
//FIXME always redirected to login after page load //FIXME always redirected to login after page load
return api.isAuthenticated$.pipe( return api.checkAuthStatus().pipe(
first(),
map((isAuthenticated) => { map((isAuthenticated) => {
if (isAuthenticated) { if (isAuthenticated) {
return true; return true;

View File

@@ -9,7 +9,8 @@
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"server": "npm run dev --workspace=server", "server": "npm run dev --workspace=server",
"client": "npm start --prefix client", "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": [ "workspaces": [
"client", "client",