mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
Refactor canactivate guards (#401)
* Refactor route guards to allow for subclassing * fix linting
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user