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 {
|
|
|
|
|
|
|
|
constructor(private router: Router) { }
|
|
|
|
|
2017-09-28 17:05:46 +02:00
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
2017-09-26 17:16:04 +02:00
|
|
|
if (localStorage.getItem('currentUser')) {
|
|
|
|
// logged in so return true
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// not logged in so redirect to login page with the return url
|
|
|
|
this.router.navigate(['/login-page'], { queryParams: { returnUrl: state.url }});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|