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