Refactor canactivate guards (#401)
* Refactor route guards to allow for subclassing * fix linting
This commit is contained in:
parent
ea90aea013
commit
fdc6f7b1d2
|
@ -9,6 +9,8 @@ import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.serv
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LockGuardService implements CanActivate {
|
export class LockGuardService implements CanActivate {
|
||||||
|
|
||||||
|
protected homepage = 'vault';
|
||||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||||
private router: Router) { }
|
private router: Router) { }
|
||||||
|
|
||||||
|
@ -19,7 +21,7 @@ export class LockGuardService implements CanActivate {
|
||||||
if (locked) {
|
if (locked) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['vault']);
|
this.router.navigate([this.homepage]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
|
ActivatedRouteSnapshot,
|
||||||
CanActivate,
|
CanActivate,
|
||||||
Router,
|
Router,
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
|
@ -9,6 +10,8 @@ import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.serv
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UnauthGuardService implements CanActivate {
|
export class UnauthGuardService implements CanActivate {
|
||||||
|
|
||||||
|
protected homepage = 'vault';
|
||||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||||
private router: Router) { }
|
private router: Router) { }
|
||||||
|
|
||||||
|
@ -19,7 +22,7 @@ export class UnauthGuardService implements CanActivate {
|
||||||
if (locked) {
|
if (locked) {
|
||||||
this.router.navigate(['lock']);
|
this.router.navigate(['lock']);
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['vault']);
|
this.router.navigate([this.homepage]);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue