19 lines
625 B
TypeScript
19 lines
625 B
TypeScript
|
import { Injectable } from '@angular/core';
|
||
|
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||
|
import { AuthService } from '../../services/auth/auth.service';
|
||
|
|
||
|
@Injectable()
|
||
|
export class AuthGuard implements CanActivate {
|
||
|
|
||
|
constructor(private auth: AuthService, private router: Router) {
|
||
|
}
|
||
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||
|
let url: string = state.url;
|
||
|
if (!this.auth.current()) {
|
||
|
this.router.navigate(['/unauthorized'], { queryParams: { returnUrl: url } });
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
}
|