This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
bee-frontend-ARCHIVED/src/app/core/guards/auth.guard.ts
2024-08-25 20:42:39 +00:00

26 lines
772 B
TypeScript

import { Injectable } from "@angular/core";
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from "@angular/router";
import { filter, map, Observable } from "rxjs";
import { AuthService } from "../services/auth.service";
@Injectable()
export class AuthGuard implements CanActivate {
constructor(
private authService: AuthService,
private router: Router
) {
}
canActivate(): Observable<boolean> | boolean {
return this.authService.currentState$.pipe(
map((currentState) => {
if (!currentState) {
this.router.navigateByUrl('/auth');
return false;
}
return true;
})
);
}
}