2017-12-18 16:55:12 +01:00
|
|
|
import { AuthService } from '../services/auth/auth.service';
|
2017-09-26 17:16:04 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AuthGuard implements CanActivate {
|
|
|
|
|
2017-12-18 16:55:12 +01:00
|
|
|
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;
|
2017-11-01 18:18:27 +01:00
|
|
|
}
|
2017-12-18 16:55:12 +01:00
|
|
|
return true;
|
2017-09-26 17:16:04 +02:00
|
|
|
}
|
2017-11-01 18:18:27 +01:00
|
|
|
}
|