mirror of
https://github.com/bitwarden/browser.git
synced 2025-02-08 00:01:28 +01:00
Merge pull request #1883 from bitwarden/use-lock-guard
Use lockGuardService to prevent back navigation
This commit is contained in:
commit
98df7190ca
@ -9,6 +9,7 @@ import {
|
||||
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
||||
|
||||
import { LaunchGuardService } from './services/launch-guard.service';
|
||||
import { LockGuardService } from './services/lock-guard.service';
|
||||
|
||||
import { EnvironmentComponent } from './accounts/environment.component';
|
||||
import { HintComponent } from './accounts/hint.component';
|
||||
@ -76,6 +77,7 @@ const routes: Routes = [
|
||||
{
|
||||
path: 'lock',
|
||||
component: LockComponent,
|
||||
canActivate: [LockGuardService],
|
||||
data: { state: 'lock' },
|
||||
},
|
||||
{
|
||||
|
@ -6,32 +6,17 @@ import {
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
|
||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
||||
import { UnauthGuardService } from './unauth-guard.service';
|
||||
|
||||
@Injectable()
|
||||
export class LaunchGuardService implements CanActivate {
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||
private router: Router) { }
|
||||
constructor(private router: Router, private unauthGuardService: UnauthGuardService) { }
|
||||
|
||||
async canActivate() {
|
||||
if (BrowserApi.getBackgroundPage() == null) {
|
||||
this.router.navigate(['private-mode']);
|
||||
return false;
|
||||
}
|
||||
|
||||
const isAuthed = await this.userService.isAuthenticated();
|
||||
if (!isAuthed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const locked = await this.vaultTimeoutService.isLocked();
|
||||
if (locked) {
|
||||
this.router.navigate(['lock']);
|
||||
} else {
|
||||
this.router.navigate(['tabs/current']);
|
||||
}
|
||||
|
||||
return false;
|
||||
return await this.unauthGuardService.canActivate();
|
||||
}
|
||||
}
|
||||
|
8
src/popup/services/lock-guard.service.ts
Normal file
8
src/popup/services/lock-guard.service.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { LockGuardService as BaseLockGuardService } from 'jslib-angular/services/lock-guard.service';
|
||||
|
||||
@Injectable()
|
||||
export class LockGuardService extends BaseLockGuardService {
|
||||
protected homepage = 'tabs/current';
|
||||
}
|
@ -6,7 +6,9 @@ import {
|
||||
|
||||
import { ToasterModule } from 'angular2-toaster';
|
||||
|
||||
import { LockGuardService } from './lock-guard.service';
|
||||
import { LaunchGuardService } from './launch-guard.service';
|
||||
import { UnauthGuardService } from './unauth-guard.service';
|
||||
|
||||
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
||||
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
|
||||
@ -116,7 +118,9 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
|
||||
providers: [
|
||||
ValidationService,
|
||||
AuthGuardService,
|
||||
LockGuardService,
|
||||
LaunchGuardService,
|
||||
UnauthGuardService,
|
||||
PopupUtilsService,
|
||||
BroadcasterService,
|
||||
{ provide: MessagingService, useValue: messagingService },
|
||||
|
8
src/popup/services/unauth-guard.service.ts
Normal file
8
src/popup/services/unauth-guard.service.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { UnauthGuardService as BaseUnauthGuardService } from 'jslib-angular/services/unauth-guard.service';
|
||||
|
||||
@Injectable()
|
||||
export class UnauthGuardService extends BaseUnauthGuardService {
|
||||
protected homepage = 'tabs/current';
|
||||
}
|
Loading…
Reference in New Issue
Block a user