generated from flo/template-frontend
26 lines
772 B
TypeScript
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;
|
|
})
|
|
);
|
|
}
|
|
} |