-
Reid Givens authoredReid Givens authored
auth-guard.service.ts 542 B
import {Injectable} from '@angular/core';
import {AuthService} from "./auth.service";
import {Router} from "@angular/router";
import {AlertService} from "./alert.service";
@Injectable({
providedIn: 'root'
})
export class AuthGuardService {
constructor(public auth: AuthService, public router: Router, private alertService: AlertService) {
}
canActivate(): boolean {
if (!this.auth.isAuthenticated()) {
this.alertService.error('Log In');
this.router.navigate(['/']);
return false;
}
return true;
}
}