mirror of
https://github.com/bitwarden/browser
synced 2026-01-05 18:13:26 +00:00
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { BrowserApi } from '../../browser/browserApi';
|
|
|
|
import { Injectable } from '@angular/core';
|
|
import {
|
|
CanActivate,
|
|
Router,
|
|
} from '@angular/router';
|
|
|
|
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
|
|
|
@Injectable()
|
|
export class LaunchGuardService implements CanActivate {
|
|
constructor(private cryptoService: CryptoService, private userService: UserService, private router: Router) { }
|
|
|
|
async canActivate() {
|
|
if (BrowserApi.getBackgroundPage() == null) {
|
|
if (BrowserApi.isEdge18) {
|
|
// tslint:disable-next-line
|
|
console.log('getBackgroundPage is null from launch guard.');
|
|
}
|
|
this.router.navigate(['private-mode']);
|
|
return false;
|
|
}
|
|
|
|
const isAuthed = await this.userService.isAuthenticated();
|
|
if (!isAuthed) {
|
|
return true;
|
|
}
|
|
|
|
const hasKey = await this.cryptoService.hasKey();
|
|
if (!hasKey) {
|
|
this.router.navigate(['lock']);
|
|
} else {
|
|
this.router.navigate(['tabs/current']);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|