mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-02 18:17:46 +01:00
Use route guards from jslib to reduce duplication
This commit is contained in:
parent
1e998094df
commit
1a143ef7c7
@ -7,9 +7,10 @@ import {
|
||||
} from '@angular/router';
|
||||
|
||||
import { AuthGuardService } from 'jslib/angular/services/auth-guard.service';
|
||||
import { LockGuardService } from 'jslib/angular/services/lock-guard.service';
|
||||
|
||||
import { LaunchGuardService } from './services/launch-guard.service';
|
||||
import { LockGuardService } from './services/lock-guard.service';
|
||||
import { NotPrivateGuardService } from './services/not-private-guard.service';
|
||||
import { UnauthGuardService } from './services/unauth-guard.service';
|
||||
|
||||
import { EnvironmentComponent } from './accounts/environment.component';
|
||||
import { HintComponent } from './accounts/hint.component';
|
||||
@ -65,13 +66,13 @@ const routes: Routes = [
|
||||
{
|
||||
path: 'home',
|
||||
component: HomeComponent,
|
||||
canActivate: [LaunchGuardService],
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
data: { state: 'home' },
|
||||
},
|
||||
{
|
||||
path: 'login',
|
||||
component: LoginComponent,
|
||||
canActivate: [LaunchGuardService],
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
data: { state: 'login' },
|
||||
},
|
||||
{
|
||||
@ -83,19 +84,19 @@ const routes: Routes = [
|
||||
{
|
||||
path: '2fa',
|
||||
component: TwoFactorComponent,
|
||||
canActivate: [LaunchGuardService],
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
data: { state: '2fa' },
|
||||
},
|
||||
{
|
||||
path: '2fa-options',
|
||||
component: TwoFactorOptionsComponent,
|
||||
canActivate: [LaunchGuardService],
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
data: { state: '2fa-options' },
|
||||
},
|
||||
{
|
||||
path: 'sso',
|
||||
component: SsoComponent,
|
||||
canActivate: [LaunchGuardService],
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
data: { state: 'sso' },
|
||||
},
|
||||
{
|
||||
@ -106,19 +107,19 @@ const routes: Routes = [
|
||||
{
|
||||
path: 'register',
|
||||
component: RegisterComponent,
|
||||
canActivate: [LaunchGuardService],
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
data: { state: 'register' },
|
||||
},
|
||||
{
|
||||
path: 'hint',
|
||||
component: HintComponent,
|
||||
canActivate: [LaunchGuardService],
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
data: { state: 'hint' },
|
||||
},
|
||||
{
|
||||
path: 'environment',
|
||||
component: EnvironmentComponent,
|
||||
canActivate: [LaunchGuardService],
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
data: { state: 'environment' },
|
||||
},
|
||||
{
|
||||
|
19
src/popup/services/lock-guard.service.ts
Normal file
19
src/popup/services/lock-guard.service.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
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 extends BaseLockGuardService {
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||
private router: Router) {
|
||||
super(vaultTimeoutService, userService, router);
|
||||
}
|
||||
|
||||
protected landingPage = '/tabs/current';
|
||||
}
|
@ -10,7 +10,7 @@ import { UserService } from 'jslib/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
|
||||
@Injectable()
|
||||
export class LaunchGuardService implements CanActivate {
|
||||
export class NotPrivateGuardService implements CanActivate {
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||
private router: Router) { }
|
||||
|
||||
@ -19,19 +19,6 @@ export class LaunchGuardService implements CanActivate {
|
||||
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;
|
||||
}
|
||||
}
|
19
src/popup/services/unauth-guard.service.ts
Normal file
19
src/popup/services/unauth-guard.service.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
|
||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
||||
|
||||
import { UnauthGuardService as BaseUnauthGuardService } from 'jslib/angular/services/unauth-guard.service';
|
||||
|
||||
@Injectable()
|
||||
export class UnauthGuardService extends BaseUnauthGuardService {
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||
private router: Router) {
|
||||
super(vaultTimeoutService, userService, router);
|
||||
}
|
||||
|
||||
protected landingPage: '/tabs/current';
|
||||
}
|
Loading…
Reference in New Issue
Block a user