UNPKG

mean-guide-frontend

Version:

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.

24 lines (21 loc) 762 B
import { CanActivate, Router } from '@angular/router'; import { AuthService } from './auth.service'; import { Injectable } from '@angular/core'; @Injectable() export class AuthGuard implements CanActivate { constructor(private authService: AuthService, private router: Router) {} canActivate( route: import('@angular/router').ActivatedRouteSnapshot, state: import('@angular/router').RouterStateSnapshot ): | boolean | import('@angular/router').UrlTree | import('rxjs').Observable<boolean | import('@angular/router').UrlTree> | Promise<boolean | import('@angular/router').UrlTree> { const isAuth = this.authService.getIsAuthenticated(); if (!isAuth){ this.router.navigate['/auth/login'] } return isAuth } }