Lots of refactor with auth guards and functional customer routing

This commit is contained in:
piratefinn 2017-08-31 18:44:17 +01:00
parent 52fbda7157
commit 24037e0454
13 changed files with 143 additions and 1017 deletions

View 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;
}
}

View 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;
}
}