1
0
mirror of https://github.com/bitwarden/desktop synced 2026-02-22 12:23:24 +00:00

[feature] Limit account switching to 5 account maximum

This commit is contained in:
addison
2021-11-16 13:54:29 -05:00
parent 0ac3328121
commit b60c36bb3f
4 changed files with 34 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ import {
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
import { LockGuardService } from 'jslib-angular/services/lock-guard.service';
import { LoginGuardService } from 'src/services/loginGuard.service';
import { HintComponent } from './accounts/hint.component';
import { LockComponent } from './accounts/lock.component';
import { LoginComponent } from './accounts/login.component';
@@ -31,6 +33,7 @@ const routes: Routes = [
{
path: 'login',
component: LoginComponent,
canActivate: [LoginGuardService],
},
{ path: '2fa', component: TwoFactorComponent },
{ path: 'register', component: RegisterComponent },

View File

@@ -128,7 +128,7 @@ const organizationService = new OrganizationService(stateService);
const providerService: ProviderServiceAbstraction = new ProviderService(stateService);
const policyService = new PolicyService(stateService, organizationService, apiService);
const keyConnectorService = new KeyConnectorService(stateService, cryptoService, apiService,
environmentService, tokenService, logService, organizationService);
tokenService, logService, organizationService);
const vaultTimeoutService = new VaultTimeoutService(cipherService, folderService, collectionService,
cryptoService, platformUtilsService, messagingService, searchService, tokenService, policyService, keyConnectorService,
stateService, null,

View File

@@ -1783,5 +1783,8 @@
},
"lockAllVaults": {
"message": "Lock All Vaults"
},
"accountLimitReached": {
"message": "No more than 5 accounts may be logged in at the same time."
}
}

View File

@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import {
CanActivate,
Router,
} from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { StateService } from 'jslib-common/abstractions/state.service';
@Injectable()
export class LoginGuardService implements CanActivate {
protected homepage = 'vault';
constructor(private stateService: StateService, private router: Router,
private toasterService: ToasterService, private i18nService: I18nService) { }
async canActivate() {
const accounts = this.stateService.accounts.getValue();
if (accounts != null && Object.keys(accounts).length >= 5) {
this.toasterService.popAsync('error', null, this.i18nService.t('accountLimitReached'));
this.router.navigate(['vault']);
}
return true;
}
}