1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

Add unauthGuard and lockGuard to prevent unintended navigation (#351)

* Lift web repo unauthGuardService up to jslib

* Add lockGuard (requires vault to be locked)

* Fix linting
This commit is contained in:
Thomas Rittson 2021-04-22 07:52:48 +10:00 committed by GitHub
parent 3c872e56f2
commit 36641f07b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import { Injectable } from '@angular/core';
import {
CanActivate,
Router,
} from '@angular/router';
import { UserService } from '../../abstractions/user.service';
import { VaultTimeoutService } from '../../abstractions/vaultTimeout.service';
@Injectable()
export class LockGuardService implements CanActivate {
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
private router: Router) { }
async canActivate() {
const locked = await this.vaultTimeoutService.isLocked();
if (!locked) {
const isAuthed = await this.userService.isAuthenticated();
if (!isAuthed) {
this.router.navigate(['login']);
} else {
this.router.navigate(['vault']);
}
return false;
}
return true;
}
}

View File

@ -0,0 +1,29 @@
import { Injectable } from '@angular/core';
import {
CanActivate,
Router,
} from '@angular/router';
import { UserService } from '../../abstractions/user.service';
import { VaultTimeoutService } from '../../abstractions/vaultTimeout.service';
@Injectable()
export class UnauthGuardService implements CanActivate {
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
private router: Router) { }
async canActivate() {
const isAuthed = await this.userService.isAuthenticated();
if (isAuthed) {
const locked = await this.vaultTimeoutService.isLocked();
if (locked) {
this.router.navigate(['lock']);
} else {
this.router.navigate(['vault']);
}
return false;
}
return true;
}
}