argos/dmp-frontend/src/app/guards/auth.guard.ts

19 lines
646 B
TypeScript
Raw Normal View History

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) { }
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;
}
}