Made guards less likely to give infinite loop
This commit is contained in:
parent
b4df7d8a64
commit
f29cf1eba5
2 changed files with 14 additions and 12 deletions
|
@ -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');
|
||||||
|
this.router.navigate(['/dashboard']);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
this.router.navigate(['/login']);
|
||||||
// customer not logged in so redirect to org dashboard
|
|
||||||
console.log('not an customer')
|
|
||||||
this.router.navigate(['/dashboard']);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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');
|
||||||
|
this.router.navigate(['/dashboard-customer']);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
this.router.navigate(['/login']);
|
||||||
// org not logged in so redirect to customer dashboard
|
|
||||||
console.log('not an organisation')
|
|
||||||
this.router.navigate(['/dashboard-customer']);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue