1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-30 15:13:22 +00:00
Files
jslib/angular/src/services/lock-guard.service.ts
Thomas Rittson fdc6f7b1d2 Refactor canactivate guards (#401)
* Refactor route guards to allow for subclassing

* fix linting
2021-06-09 07:35:03 +10:00

33 lines
946 B
TypeScript

import { Injectable } from '@angular/core';
import {
CanActivate,
Router,
} from '@angular/router';
import { UserService } from 'jslib-common/abstractions/user.service';
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
@Injectable()
export class LockGuardService implements CanActivate {
protected homepage = 'vault';
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) {
return true;
} else {
this.router.navigate([this.homepage]);
return false;
}
}
this.router.navigate(['']);
return false;
}
}