1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-28 17:27:50 +01:00

Use jslib unauthGuard, add lockGuard support (#939)

* Use jslib unauthGuard, add lockGuard support

* bump jslib
This commit is contained in:
Thomas Rittson 2021-04-22 18:13:43 +10:00 committed by GitHub
parent 714a574028
commit 9b38095aba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 40 deletions

2
jslib

@ -1 +1 @@
Subproject commit 3c872e56f27ae78fb922b765d7601886b5c39f78 Subproject commit 36641f07b9807d90270ccd743d16b903cb558078

View File

@ -33,13 +33,6 @@ export class LockComponent extends BaseLockComponent {
async ngOnInit() { async ngOnInit() {
await super.ngOnInit(); await super.ngOnInit();
const authed = await this.userService.isAuthenticated();
if (!authed) {
this.router.navigate(['/']);
} else if (await this.cryptoService.hasKey()) {
this.router.navigate(['vault']);
}
this.onSuccessfulSubmit = () => { this.onSuccessfulSubmit = () => {
const previousUrl = this.routerService.getPreviousUrl(); const previousUrl = this.routerService.getPreviousUrl();
if (previousUrl !== '/' && previousUrl.indexOf('lock') === -1) { if (previousUrl !== '/' && previousUrl.indexOf('lock') === -1) {

View File

@ -87,9 +87,10 @@ import { VaultComponent } from './vault/vault.component';
import { OrganizationGuardService } from './services/organization-guard.service'; import { OrganizationGuardService } from './services/organization-guard.service';
import { OrganizationTypeGuardService } from './services/organization-type-guard.service'; import { OrganizationTypeGuardService } from './services/organization-type-guard.service';
import { UnauthGuardService } from './services/unauth-guard.service';
import { AuthGuardService } from 'jslib/angular/services/auth-guard.service'; import { AuthGuardService } from 'jslib/angular/services/auth-guard.service';
import { LockGuardService } from 'jslib/angular/services/lock-guard.service';
import { UnauthGuardService } from 'jslib/angular/services/unauth-guard.service';
import { Permissions } from 'jslib/enums/permissions'; import { Permissions } from 'jslib/enums/permissions';
@ -122,7 +123,11 @@ const routes: Routes = [
canActivate: [UnauthGuardService], canActivate: [UnauthGuardService],
data: { titleId: 'passwordHint' }, data: { titleId: 'passwordHint' },
}, },
{ path: 'lock', component: LockComponent }, {
path: 'lock',
component: LockComponent,
canActivate: [LockGuardService],
},
{ path: 'verify-email', component: VerifyEmailTokenComponent }, { path: 'verify-email', component: VerifyEmailTokenComponent },
{ {
path: 'accept-organization', path: 'accept-organization',

View File

@ -16,10 +16,11 @@ import { EventService } from './event.service';
import { OrganizationGuardService } from './organization-guard.service'; import { OrganizationGuardService } from './organization-guard.service';
import { OrganizationTypeGuardService } from './organization-type-guard.service'; import { OrganizationTypeGuardService } from './organization-type-guard.service';
import { RouterService } from './router.service'; import { RouterService } from './router.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';
import { LockGuardService } from 'jslib/angular/services/lock-guard.service';
import { UnauthGuardService } from 'jslib/angular/services/unauth-guard.service';
import { ValidationService } from 'jslib/angular/services/validation.service'; import { ValidationService } from 'jslib/angular/services/validation.service';
import { ApiService } from 'jslib/services/api.service'; import { ApiService } from 'jslib/services/api.service';
@ -190,6 +191,7 @@ export function initFactory(): Function {
UnauthGuardService, UnauthGuardService,
RouterService, RouterService,
EventService, EventService,
LockGuardService,
{ provide: AuditServiceAbstraction, useValue: auditService }, { provide: AuditServiceAbstraction, useValue: auditService },
{ provide: AuthServiceAbstraction, useValue: authService }, { provide: AuthServiceAbstraction, useValue: authService },
{ provide: CipherServiceAbstraction, useValue: cipherService }, { provide: CipherServiceAbstraction, useValue: cipherService },

View File

@ -1,29 +0,0 @@
import { Injectable } from '@angular/core';
import {
CanActivate,
Router,
} from '@angular/router';
import { UserService } from 'jslib/abstractions/user.service';
import { VaultTimeoutService } from 'jslib/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;
}
}