25 lines
715 B
TypeScript
25 lines
715 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router, UrlTree } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { AuthenticationService } from '../_services/authentication.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class AuthGuard implements CanActivate {
|
|
|
|
constructor(private _authService: AuthenticationService, private router: Router){}
|
|
|
|
canActivate(
|
|
next: ActivatedRouteSnapshot,
|
|
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean | UrlTree {
|
|
if (this._authService.IsLoggedIn){
|
|
return true;
|
|
}
|
|
else {
|
|
return this.router.parseUrl('/home');
|
|
}
|
|
}
|
|
}
|