This repository has been archived on 2026-05-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
PolyNotFound/src/app/utils/my-guard/my-guard.guard.ts
2021-12-24 12:14:20 +01:00

25 lines
754 B
TypeScript

import { Injectable } from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
import { Observable } from 'rxjs';
import {ProfilService} from "../profil/profil.service";
@Injectable({
providedIn: 'root'
})
export class MyGuardGuard implements CanActivate
{
constructor(private profilService: ProfilService, private router: Router) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree
{
if(this.profilService.getId() !== "") return true;
else {
this.router.navigateByUrl("login");
return false;
}
}
}