Skip to content
Permalink
wip f51adeb Mar 24, 2019
1 contributor

Users who have contributed to this file

17 lines (12 sloc) 599 Bytes
import { Injectable } from '@angular/core';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router, private authService: AuthService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if (this.authService.isAuthenticated()) { return true; }
this.router.navigate(['/login'], { queryParams: { redirect: state.url }, replaceUrl: true });
return false;
}
}
You can’t perform that action at this time.