Merge pull request #6 from Pear-Trading/TBSliver/Guard-Fixes

Made guards less likely to give infinite loop
This commit is contained in:
Tom Bloor 2017-09-05 11:42:17 +01:00 committed by GitHub
commit e0a78c0f43
2 changed files with 14 additions and 12 deletions

View file

@ -7,15 +7,16 @@ export class CustomerGuard implements CanActivate {
constructor(private router: Router) { } constructor(private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (localStorage.getItem('usertype') == 'customer') { if (localStorage.getItem('usertype') === 'customer') {
console.log('Customer logged in') console.log('Customer logged in');
// customer logged in so return true // customer logged in so return true
return true; return true;
} } else if (localStorage.getItem('usertype') === 'organisation') {
console.log('not an customer');
// customer not logged in so redirect to org dashboard
console.log('not an customer')
this.router.navigate(['/dashboard']); this.router.navigate(['/dashboard']);
return false; return false;
} }
this.router.navigate(['/login']);
return false;
}
} }

View file

@ -7,15 +7,16 @@ export class OrgGuard implements CanActivate {
constructor(private router: Router) { } constructor(private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (localStorage.getItem('usertype') == 'organisation') { if (localStorage.getItem('usertype') === 'organisation') {
console.log('Organisation logged in') console.log('Organisation logged in');
// org logged in so return true // org logged in so return true
return true; return true;
} } else if (localStorage.getItem('usertype') === 'customer') {
console.log('not an organisation');
// org not logged in so redirect to customer dashboard
console.log('not an organisation')
this.router.navigate(['/dashboard-customer']); this.router.navigate(['/dashboard-customer']);
return false; return false;
} }
this.router.navigate(['/login']);
return false;
}
} }