Lots of refactor with auth guards and functional customer routing
This commit is contained in:
parent
52fbda7157
commit
24037e0454
13 changed files with 143 additions and 1017 deletions
21
src/app/_guards/customer.guard.ts
Normal file
21
src/app/_guards/customer.guard.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||
|
||||
@Injectable()
|
||||
export class CustomerGuard implements CanActivate {
|
||||
|
||||
constructor(private router: Router) { }
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
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')
|
||||
this.router.navigate(['/dashboard']);
|
||||
return false;
|
||||
}
|
||||
}
|
21
src/app/_guards/org.guard.ts
Normal file
21
src/app/_guards/org.guard.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||
|
||||
@Injectable()
|
||||
export class OrgGuard implements CanActivate {
|
||||
|
||||
constructor(private router: Router) { }
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
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')
|
||||
this.router.navigate(['/dashboard-customer']);
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in a new issue