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 { return this.authService.currentState$.pipe( map((currentState) => { if (!currentState) { this.router.navigateByUrl('/auth'); return false; } return true; }) ); } }