Refactor canactivate guards (#401)

* Refactor route guards to allow for subclassing

* fix linting
This commit is contained in:
Thomas Rittson 2021-06-08 14:35:03 -07:00 committed by GitHub
parent ea90aea013
commit fdc6f7b1d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

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

View File

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