mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
Merge pull request #1883 from bitwarden/use-lock-guard
Use lockGuardService to prevent back navigation
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
||||||
|
|
||||||
import { LaunchGuardService } from './services/launch-guard.service';
|
import { LaunchGuardService } from './services/launch-guard.service';
|
||||||
|
import { LockGuardService } from './services/lock-guard.service';
|
||||||
|
|
||||||
import { EnvironmentComponent } from './accounts/environment.component';
|
import { EnvironmentComponent } from './accounts/environment.component';
|
||||||
import { HintComponent } from './accounts/hint.component';
|
import { HintComponent } from './accounts/hint.component';
|
||||||
@@ -76,6 +77,7 @@ const routes: Routes = [
|
|||||||
{
|
{
|
||||||
path: 'lock',
|
path: 'lock',
|
||||||
component: LockComponent,
|
component: LockComponent,
|
||||||
|
canActivate: [LockGuardService],
|
||||||
data: { state: 'lock' },
|
data: { state: 'lock' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,32 +6,17 @@ import {
|
|||||||
Router,
|
Router,
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
|
|
||||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
import { UnauthGuardService } from './unauth-guard.service';
|
||||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LaunchGuardService implements CanActivate {
|
export class LaunchGuardService implements CanActivate {
|
||||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
constructor(private router: Router, private unauthGuardService: UnauthGuardService) { }
|
||||||
private router: Router) { }
|
|
||||||
|
|
||||||
async canActivate() {
|
async canActivate() {
|
||||||
if (BrowserApi.getBackgroundPage() == null) {
|
if (BrowserApi.getBackgroundPage() == null) {
|
||||||
this.router.navigate(['private-mode']);
|
this.router.navigate(['private-mode']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return await this.unauthGuardService.canActivate();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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 { ToasterModule } from 'angular2-toaster';
|
||||||
|
|
||||||
|
import { LockGuardService } from './lock-guard.service';
|
||||||
import { LaunchGuardService } from './launch-guard.service';
|
import { LaunchGuardService } from './launch-guard.service';
|
||||||
|
import { UnauthGuardService } from './unauth-guard.service';
|
||||||
|
|
||||||
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
||||||
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
|
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
|
||||||
@@ -116,7 +118,9 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
|
|||||||
providers: [
|
providers: [
|
||||||
ValidationService,
|
ValidationService,
|
||||||
AuthGuardService,
|
AuthGuardService,
|
||||||
|
LockGuardService,
|
||||||
LaunchGuardService,
|
LaunchGuardService,
|
||||||
|
UnauthGuardService,
|
||||||
PopupUtilsService,
|
PopupUtilsService,
|
||||||
BroadcasterService,
|
BroadcasterService,
|
||||||
{ provide: MessagingService, useValue: messagingService },
|
{ 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';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user