Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Refactor canactivate guards (#401)
Browse files Browse the repository at this point in the history
* Refactor route guards to allow for subclassing

* fix linting
  • Loading branch information
eliykat committed Jun 8, 2021
1 parent ea90aea commit fdc6f7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion angular/src/services/lock-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.serv

@Injectable()
export class LockGuardService implements CanActivate {

protected homepage = 'vault';
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
private router: Router) { }

Expand All @@ -19,7 +21,7 @@ export class LockGuardService implements CanActivate {
if (locked) {
return true;
} else {
this.router.navigate(['vault']);
this.router.navigate([this.homepage]);
return false;
}
}
Expand Down
5 changes: 4 additions & 1 deletion angular/src/services/unauth-guard.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
} from '@angular/router';
Expand All @@ -9,6 +10,8 @@ import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.serv

@Injectable()
export class UnauthGuardService implements CanActivate {

protected homepage = 'vault';
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
private router: Router) { }

Expand All @@ -19,7 +22,7 @@ export class UnauthGuardService implements CanActivate {
if (locked) {
this.router.navigate(['lock']);
} else {
this.router.navigate(['vault']);
this.router.navigate([this.homepage]);
}
return false;
}
Expand Down

0 comments on commit fdc6f7b

Please sign in to comment.