fix: auth guard
This commit is contained in:
@@ -20,15 +20,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);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
Reference in New Issue
Block a user