diff --git a/apps/browser/src/vault/popup/components/vault-v2/vault-generator-dialog/vault-generator-dialog.component.html b/apps/browser/src/vault/popup/components/vault-v2/vault-generator-dialog/vault-generator-dialog.component.html
index 72aaeea493d..4301489156a 100644
--- a/apps/browser/src/vault/popup/components/vault-v2/vault-generator-dialog/vault-generator-dialog.component.html
+++ b/apps/browser/src/vault/popup/components/vault-v2/vault-generator-dialog/vault-generator-dialog.component.html
@@ -8,6 +8,7 @@
diff --git a/apps/browser/src/vault/popup/components/vault-v2/vault-generator-dialog/vault-generator-dialog.component.ts b/apps/browser/src/vault/popup/components/vault-v2/vault-generator-dialog/vault-generator-dialog.component.ts
index d050312211b..48f4dcad211 100644
--- a/apps/browser/src/vault/popup/components/vault-v2/vault-generator-dialog/vault-generator-dialog.component.ts
+++ b/apps/browser/src/vault/popup/components/vault-v2/vault-generator-dialog/vault-generator-dialog.component.ts
@@ -4,7 +4,9 @@ import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog";
import { Overlay } from "@angular/cdk/overlay";
import { CommonModule } from "@angular/common";
import { Component, Inject } from "@angular/core";
+import { Subject, takeUntil } from "rxjs";
+import { AccountService, Account } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ButtonModule, DialogService } from "@bitwarden/components";
import { CipherFormGeneratorComponent } from "@bitwarden/vault";
@@ -60,11 +62,26 @@ export class VaultGeneratorDialogComponent {
*/
protected generatedValue: string = "";
+ /**
+ * The currently active account.
+ */
+ protected account: Account | null = null;
+
+ /**
+ * Emits when the component is destroyed to clean up subscriptions.
+ */
+ private readonly destroyed$ = new Subject();
+
constructor(
@Inject(DIALOG_DATA) protected params: GeneratorDialogParams,
private dialogRef: DialogRef,
private i18nService: I18nService,
- ) {}
+ private accountService: AccountService,
+ ) {
+ this.accountService.activeAccount$.pipe(takeUntil(this.destroyed$)).subscribe((account) => {
+ this.account = account;
+ });
+ }
/**
* Close the dialog without selecting a value.
diff --git a/apps/web/src/app/vault/components/web-generator-dialog/web-generator-dialog.component.html b/apps/web/src/app/vault/components/web-generator-dialog/web-generator-dialog.component.html
index e224d1d19cc..6a3b287139d 100644
--- a/apps/web/src/app/vault/components/web-generator-dialog/web-generator-dialog.component.html
+++ b/apps/web/src/app/vault/components/web-generator-dialog/web-generator-dialog.component.html
@@ -6,6 +6,7 @@
diff --git a/apps/web/src/app/vault/components/web-generator-dialog/web-generator-dialog.component.ts b/apps/web/src/app/vault/components/web-generator-dialog/web-generator-dialog.component.ts
index d21403dd4e5..2e7a5e97b24 100644
--- a/apps/web/src/app/vault/components/web-generator-dialog/web-generator-dialog.component.ts
+++ b/apps/web/src/app/vault/components/web-generator-dialog/web-generator-dialog.component.ts
@@ -3,7 +3,9 @@
import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog";
import { CommonModule } from "@angular/common";
import { Component, Inject } from "@angular/core";
+import { takeUntil, Subject } from "rxjs";
+import { AccountService, Account } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ButtonModule, DialogModule, DialogService } from "@bitwarden/components";
import { CipherFormGeneratorComponent } from "@bitwarden/vault";
@@ -48,11 +50,26 @@ export class WebVaultGeneratorDialogComponent {
*/
protected generatedValue: string = "";
+ /**
+ * The currently active account.
+ */
+ protected account: Account | null = null;
+
+ /**
+ * Emits when the component is destroyed to clean up subscriptions.
+ */
+ private readonly destroyed$ = new Subject();
+
constructor(
@Inject(DIALOG_DATA) protected params: WebVaultGeneratorDialogParams,
private dialogRef: DialogRef,
private i18nService: I18nService,
- ) {}
+ private accountService: AccountService,
+ ) {
+ this.accountService.activeAccount$.pipe(takeUntil(this.destroyed$)).subscribe((account) => {
+ this.account = account;
+ });
+ }
/**
* Close the dialog without selecting a value.
diff --git a/libs/tools/generator/components/src/catchall-settings.component.ts b/libs/tools/generator/components/src/catchall-settings.component.ts
index 8d5793354d7..d49a6b9dc2f 100644
--- a/libs/tools/generator/components/src/catchall-settings.component.ts
+++ b/libs/tools/generator/components/src/catchall-settings.component.ts
@@ -4,7 +4,7 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angu
import { FormBuilder } from "@angular/forms";
import { BehaviorSubject, map, skip, Subject, takeUntil, withLatestFrom } from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { UserId } from "@bitwarden/common/types/guid";
import {
CatchallGenerationOptions,
@@ -12,8 +12,6 @@ import {
Generators,
} from "@bitwarden/generator-core";
-import { completeOnAccountSwitch } from "./util";
-
/** Options group for catchall emails */
@Component({
selector: "tools-catchall-settings",
@@ -21,16 +19,16 @@ import { completeOnAccountSwitch } from "./util";
})
export class CatchallSettingsComponent implements OnInit, OnDestroy {
/** Instantiates the component
- * @param accountService queries user availability
* @param generatorService settings and policy logic
* @param formBuilder reactive form controls
*/
constructor(
private formBuilder: FormBuilder,
private generatorService: CredentialGeneratorService,
- private accountService: AccountService,
) {}
+ @Input() account: Account | null = null;
+
/** Binds the component to a specific user's settings.
* When this input is not provided, the form binds to the active
* user
@@ -84,10 +82,11 @@ export class CatchallSettingsComponent implements OnInit, OnDestroy {
return new BehaviorSubject(this.userId as UserId).asObservable();
}
- return this.accountService.activeAccount$.pipe(
- completeOnAccountSwitch(),
- takeUntil(this.destroyed$),
- );
+ if (this.account) {
+ return new BehaviorSubject(this.account.id as UserId).asObservable();
+ }
+
+ return new BehaviorSubject(null).asObservable();
}
private readonly destroyed$ = new Subject();
diff --git a/libs/tools/generator/components/src/credential-generator-history-dialog.component.ts b/libs/tools/generator/components/src/credential-generator-history-dialog.component.ts
index 7bcffd92399..b4fa529a215 100644
--- a/libs/tools/generator/components/src/credential-generator-history-dialog.component.ts
+++ b/libs/tools/generator/components/src/credential-generator-history-dialog.component.ts
@@ -2,12 +2,12 @@
// @ts-strict-ignore
import { DialogRef } from "@angular/cdk/dialog";
import { CommonModule } from "@angular/common";
-import { Component } from "@angular/core";
+import { Component, Input } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
-import { BehaviorSubject, distinctUntilChanged, firstValueFrom, map, switchMap } from "rxjs";
+import { BehaviorSubject, firstValueFrom, map, switchMap } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { UserId } from "@bitwarden/common/types/guid";
import { ButtonModule, DialogModule, DialogService } from "@bitwarden/components";
import { GeneratorHistoryService } from "@bitwarden/generator-history";
@@ -28,22 +28,18 @@ import { EmptyCredentialHistoryComponent } from "./empty-credential-history.comp
],
})
export class CredentialGeneratorHistoryDialogComponent {
+ @Input() account: Account | null = null;
protected readonly hasHistory$ = new BehaviorSubject(false);
protected readonly userId$ = new BehaviorSubject(null);
constructor(
- private accountService: AccountService,
private history: GeneratorHistoryService,
private dialogService: DialogService,
private dialogRef: DialogRef,
) {
- this.accountService.activeAccount$
- .pipe(
- takeUntilDestroyed(),
- map(({ id }) => id),
- distinctUntilChanged(),
- )
- .subscribe(this.userId$);
+ if (this.account) {
+ this.userId$.next(this.account.id);
+ }
this.userId$
.pipe(
diff --git a/libs/tools/generator/components/src/credential-generator-history.component.ts b/libs/tools/generator/components/src/credential-generator-history.component.ts
index 69ed0b0336d..0925fe9009b 100644
--- a/libs/tools/generator/components/src/credential-generator-history.component.ts
+++ b/libs/tools/generator/components/src/credential-generator-history.component.ts
@@ -1,13 +1,13 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { CommonModule } from "@angular/common";
-import { Component } from "@angular/core";
+import { Component, Input } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { RouterLink } from "@angular/router";
-import { BehaviorSubject, distinctUntilChanged, map, switchMap } from "rxjs";
+import { BehaviorSubject, map, switchMap } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { UserId } from "@bitwarden/common/types/guid";
import {
ColorPasswordModule,
@@ -40,21 +40,17 @@ import { GeneratorModule } from "./generator.module";
],
})
export class CredentialGeneratorHistoryComponent {
+ @Input() account: Account | null = null;
protected readonly userId$ = new BehaviorSubject(null);
protected readonly credentials$ = new BehaviorSubject([]);
constructor(
- private accountService: AccountService,
private generatorService: CredentialGeneratorService,
private history: GeneratorHistoryService,
) {
- this.accountService.activeAccount$
- .pipe(
- takeUntilDestroyed(),
- map(({ id }) => id),
- distinctUntilChanged(),
- )
- .subscribe(this.userId$);
+ if (this.account) {
+ this.userId$.next(this.account.id);
+ }
this.userId$
.pipe(
diff --git a/libs/tools/generator/components/src/credential-generator.component.ts b/libs/tools/generator/components/src/credential-generator.component.ts
index a2b204eaca4..7a3eaa40603 100644
--- a/libs/tools/generator/components/src/credential-generator.component.ts
+++ b/libs/tools/generator/components/src/credential-generator.component.ts
@@ -17,7 +17,7 @@ import {
withLatestFrom,
} from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { IntegrationId } from "@bitwarden/common/tools/integration";
@@ -57,7 +57,6 @@ export class CredentialGeneratorComponent implements OnInit, OnDestroy {
private toastService: ToastService,
private logService: LogService,
private i18nService: I18nService,
- private accountService: AccountService,
private zone: NgZone,
private formBuilder: FormBuilder,
) {}
@@ -68,6 +67,9 @@ export class CredentialGeneratorComponent implements OnInit, OnDestroy {
@Input()
userId: UserId | null;
+ @Input()
+ account: Account | null = null;
+
/** Emits credentials created from a generation request. */
@Output()
readonly onGenerated = new EventEmitter();
@@ -97,13 +99,9 @@ export class CredentialGeneratorComponent implements OnInit, OnDestroy {
if (this.userId) {
this.userId$.next(this.userId);
} else {
- this.accountService.activeAccount$
- .pipe(
- map((acct) => acct.id),
- distinctUntilChanged(),
- takeUntil(this.destroyed),
- )
- .subscribe(this.userId$);
+ if (this.account) {
+ this.userId$.next(this.account.id);
+ }
}
this.generatorService
diff --git a/libs/tools/generator/components/src/forwarder-settings.component.ts b/libs/tools/generator/components/src/forwarder-settings.component.ts
index 114ab4c3b92..b82904453b4 100644
--- a/libs/tools/generator/components/src/forwarder-settings.component.ts
+++ b/libs/tools/generator/components/src/forwarder-settings.component.ts
@@ -23,7 +23,7 @@ import {
withLatestFrom,
} from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { IntegrationId } from "@bitwarden/common/tools/integration";
import { UserId } from "@bitwarden/common/types/guid";
import {
@@ -34,8 +34,6 @@ import {
toCredentialGeneratorConfiguration,
} from "@bitwarden/generator-core";
-import { completeOnAccountSwitch } from "./util";
-
const Controls = Object.freeze({
domain: "domain",
token: "token",
@@ -49,14 +47,12 @@ const Controls = Object.freeze({
})
export class ForwarderSettingsComponent implements OnInit, OnChanges, OnDestroy {
/** Instantiates the component
- * @param accountService queries user availability
* @param generatorService settings and policy logic
* @param formBuilder reactive form controls
*/
constructor(
private formBuilder: FormBuilder,
private generatorService: CredentialGeneratorService,
- private accountService: AccountService,
) {}
/** Binds the component to a specific user's settings.
@@ -66,6 +62,9 @@ export class ForwarderSettingsComponent implements OnInit, OnChanges, OnDestroy
@Input()
userId: UserId | null;
+ @Input()
+ account: Account | null = null;
+
@Input({ required: true })
forwarder: IntegrationId;
@@ -170,10 +169,11 @@ export class ForwarderSettingsComponent implements OnInit, OnChanges, OnDestroy
return new BehaviorSubject(this.userId as UserId).asObservable();
}
- return this.accountService.activeAccount$.pipe(
- completeOnAccountSwitch(),
- takeUntil(this.destroyed$),
- );
+ if (this.account) {
+ return new BehaviorSubject(this.account.id as UserId).asObservable();
+ }
+
+ return new BehaviorSubject(null).asObservable();
}
private readonly refresh$ = new Subject();
diff --git a/libs/tools/generator/components/src/passphrase-settings.component.ts b/libs/tools/generator/components/src/passphrase-settings.component.ts
index ae6a0f89966..a5a1e8d5cc6 100644
--- a/libs/tools/generator/components/src/passphrase-settings.component.ts
+++ b/libs/tools/generator/components/src/passphrase-settings.component.ts
@@ -13,7 +13,7 @@ import {
ReplaySubject,
} from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { UserId } from "@bitwarden/common/types/guid";
import {
@@ -22,8 +22,6 @@ import {
PassphraseGenerationOptions,
} from "@bitwarden/generator-core";
-import { completeOnAccountSwitch } from "./util";
-
const Controls = Object.freeze({
numWords: "numWords",
includeNumber: "includeNumber",
@@ -38,7 +36,6 @@ const Controls = Object.freeze({
})
export class PassphraseSettingsComponent implements OnInit, OnDestroy {
/** Instantiates the component
- * @param accountService queries user availability
* @param generatorService settings and policy logic
* @param i18nService localize hints
* @param formBuilder reactive form controls
@@ -47,7 +44,6 @@ export class PassphraseSettingsComponent implements OnInit, OnDestroy {
private formBuilder: FormBuilder,
private generatorService: CredentialGeneratorService,
private i18nService: I18nService,
- private accountService: AccountService,
) {}
/** Binds the component to a specific user's settings.
@@ -57,6 +53,9 @@ export class PassphraseSettingsComponent implements OnInit, OnDestroy {
@Input()
userId: UserId | null;
+ @Input()
+ account: Account | null = null;
+
/** When `true`, an options header is displayed by the component. Otherwise, the header is hidden. */
@Input()
showHeader: boolean = true;
@@ -159,10 +158,11 @@ export class PassphraseSettingsComponent implements OnInit, OnDestroy {
return new BehaviorSubject(this.userId as UserId).asObservable();
}
- return this.accountService.activeAccount$.pipe(
- completeOnAccountSwitch(),
- takeUntil(this.destroyed$),
- );
+ if (this.account) {
+ return new BehaviorSubject(this.account.id as UserId).asObservable();
+ }
+
+ return new BehaviorSubject(null).asObservable();
}
private readonly destroyed$ = new Subject();
diff --git a/libs/tools/generator/components/src/password-generator.component.html b/libs/tools/generator/components/src/password-generator.component.html
index a6aa5ebdd02..8ddc13be7a8 100644
--- a/libs/tools/generator/components/src/password-generator.component.html
+++ b/libs/tools/generator/components/src/password-generator.component.html
@@ -40,6 +40,7 @@
class="tw-mt-6"
*ngIf="(algorithm$ | async)?.id === 'password'"
[userId]="this.userId$ | async"
+ [account]="account"
[disableMargin]="disableMargin"
(onUpdated)="generate('password settings')"
/>
@@ -47,6 +48,7 @@
class="tw-mt-6"
*ngIf="(algorithm$ | async)?.id === 'passphrase'"
[userId]="this.userId$ | async"
+ [account]="account"
(onUpdated)="generate('passphrase settings')"
[disableMargin]="disableMargin"
/>
diff --git a/libs/tools/generator/components/src/password-generator.component.ts b/libs/tools/generator/components/src/password-generator.component.ts
index 85363412ffa..c801d8c037a 100644
--- a/libs/tools/generator/components/src/password-generator.component.ts
+++ b/libs/tools/generator/components/src/password-generator.component.ts
@@ -15,7 +15,7 @@ import {
withLatestFrom,
} from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { UserId } from "@bitwarden/common/types/guid";
@@ -43,10 +43,11 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
private toastService: ToastService,
private logService: LogService,
private i18nService: I18nService,
- private accountService: AccountService,
private zone: NgZone,
) {}
+ @Input() account: Account | null = null;
+
/** Binds the component to a specific user's settings.
* When this input is not provided, the form binds to the active
* user
@@ -101,13 +102,9 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
if (this.userId) {
this.userId$.next(this.userId);
} else {
- this.accountService.activeAccount$
- .pipe(
- map((acct) => acct.id),
- distinctUntilChanged(),
- takeUntil(this.destroyed),
- )
- .subscribe(this.userId$);
+ if (this.account) {
+ this.userId$.next(this.account.id);
+ }
}
this.generatorService
diff --git a/libs/tools/generator/components/src/password-settings.component.ts b/libs/tools/generator/components/src/password-settings.component.ts
index b512aa688fa..1a8bb2fbcda 100644
--- a/libs/tools/generator/components/src/password-settings.component.ts
+++ b/libs/tools/generator/components/src/password-settings.component.ts
@@ -15,7 +15,7 @@ import {
withLatestFrom,
} from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { UserId } from "@bitwarden/common/types/guid";
import {
@@ -24,8 +24,6 @@ import {
PasswordGenerationOptions,
} from "@bitwarden/generator-core";
-import { completeOnAccountSwitch } from "./util";
-
const Controls = Object.freeze({
length: "length",
uppercase: "uppercase",
@@ -44,7 +42,6 @@ const Controls = Object.freeze({
})
export class PasswordSettingsComponent implements OnInit, OnDestroy {
/** Instantiates the component
- * @param accountService queries user availability
* @param generatorService settings and policy logic
* @param i18nService localize hints
* @param formBuilder reactive form controls
@@ -53,7 +50,6 @@ export class PasswordSettingsComponent implements OnInit, OnDestroy {
private formBuilder: FormBuilder,
private generatorService: CredentialGeneratorService,
private i18nService: I18nService,
- private accountService: AccountService,
) {}
/** Binds the password component to a specific user's settings.
@@ -63,6 +59,9 @@ export class PasswordSettingsComponent implements OnInit, OnDestroy {
@Input()
userId: UserId | null;
+ @Input()
+ account: Account | null = null;
+
/** When `true`, an options header is displayed by the component. Otherwise, the header is hidden. */
@Input()
showHeader: boolean = true;
@@ -250,10 +249,11 @@ export class PasswordSettingsComponent implements OnInit, OnDestroy {
return new BehaviorSubject(this.userId as UserId).asObservable();
}
- return this.accountService.activeAccount$.pipe(
- completeOnAccountSwitch(),
- takeUntil(this.destroyed$),
- );
+ if (this.account) {
+ return new BehaviorSubject(this.account.id as UserId).asObservable();
+ }
+
+ return new BehaviorSubject(null).asObservable();
}
private readonly destroyed$ = new Subject();
diff --git a/libs/tools/generator/components/src/subaddress-settings.component.ts b/libs/tools/generator/components/src/subaddress-settings.component.ts
index 0ff826373fb..2feeec90f4b 100644
--- a/libs/tools/generator/components/src/subaddress-settings.component.ts
+++ b/libs/tools/generator/components/src/subaddress-settings.component.ts
@@ -4,7 +4,7 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angu
import { FormBuilder } from "@angular/forms";
import { BehaviorSubject, map, skip, Subject, takeUntil, withLatestFrom } from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { UserId } from "@bitwarden/common/types/guid";
import {
CredentialGeneratorService,
@@ -12,8 +12,6 @@ import {
SubaddressGenerationOptions,
} from "@bitwarden/generator-core";
-import { completeOnAccountSwitch } from "./util";
-
/** Options group for plus-addressed emails */
@Component({
selector: "tools-subaddress-settings",
@@ -21,14 +19,12 @@ import { completeOnAccountSwitch } from "./util";
})
export class SubaddressSettingsComponent implements OnInit, OnDestroy {
/** Instantiates the component
- * @param accountService queries user availability
* @param generatorService settings and policy logic
* @param formBuilder reactive form controls
*/
constructor(
private formBuilder: FormBuilder,
private generatorService: CredentialGeneratorService,
- private accountService: AccountService,
) {}
/** Binds the component to a specific user's settings.
@@ -38,6 +34,9 @@ export class SubaddressSettingsComponent implements OnInit, OnDestroy {
@Input()
userId: UserId | null;
+ @Input()
+ account: Account | null = null;
+
/** Emits settings updates and completes if the settings become unavailable.
* @remarks this does not emit the initial settings. If you would like
* to receive live settings updates including the initial update,
@@ -83,10 +82,11 @@ export class SubaddressSettingsComponent implements OnInit, OnDestroy {
return new BehaviorSubject(this.userId as UserId).asObservable();
}
- return this.accountService.activeAccount$.pipe(
- completeOnAccountSwitch(),
- takeUntil(this.destroyed$),
- );
+ if (this.account) {
+ return new BehaviorSubject(this.account.id as UserId).asObservable();
+ }
+
+ return new BehaviorSubject(null).asObservable();
}
private readonly destroyed$ = new Subject();
diff --git a/libs/tools/generator/components/src/username-generator.component.html b/libs/tools/generator/components/src/username-generator.component.html
index a5effcc0f99..e126febf0e1 100644
--- a/libs/tools/generator/components/src/username-generator.component.html
+++ b/libs/tools/generator/components/src/username-generator.component.html
@@ -61,21 +61,25 @@
diff --git a/libs/tools/generator/components/src/username-generator.component.ts b/libs/tools/generator/components/src/username-generator.component.ts
index 63c1adc602b..f6de7486e65 100644
--- a/libs/tools/generator/components/src/username-generator.component.ts
+++ b/libs/tools/generator/components/src/username-generator.component.ts
@@ -18,7 +18,7 @@ import {
withLatestFrom,
} from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { IntegrationId } from "@bitwarden/common/tools/integration";
@@ -53,7 +53,6 @@ export class UsernameGeneratorComponent implements OnInit, OnDestroy {
/** Instantiates the username generator
* @param generatorService generates credentials; stores preferences
* @param i18nService localizes generator algorithm descriptions
- * @param accountService discovers the active user when one is not provided
* @param zone detects generator settings updates originating from the generator services
* @param formBuilder binds reactive form
*/
@@ -63,11 +62,12 @@ export class UsernameGeneratorComponent implements OnInit, OnDestroy {
private toastService: ToastService,
private logService: LogService,
private i18nService: I18nService,
- private accountService: AccountService,
private zone: NgZone,
private formBuilder: FormBuilder,
) {}
+ @Input() account: Account | null = null;
+
/** Binds the component to a specific user's settings. When this input is not provided,
* the form binds to the active user
*/
@@ -98,13 +98,9 @@ export class UsernameGeneratorComponent implements OnInit, OnDestroy {
if (this.userId) {
this.userId$.next(this.userId);
} else {
- this.accountService.activeAccount$
- .pipe(
- map((acct) => acct.id),
- distinctUntilChanged(),
- takeUntil(this.destroyed),
- )
- .subscribe(this.userId$);
+ if (this.account) {
+ this.userId$.next(this.account.id);
+ }
}
this.generatorService
diff --git a/libs/tools/generator/components/src/username-settings.component.ts b/libs/tools/generator/components/src/username-settings.component.ts
index bd27861581b..0ead13dedd8 100644
--- a/libs/tools/generator/components/src/username-settings.component.ts
+++ b/libs/tools/generator/components/src/username-settings.component.ts
@@ -4,7 +4,7 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angu
import { FormBuilder } from "@angular/forms";
import { BehaviorSubject, map, skip, Subject, takeUntil, withLatestFrom } from "rxjs";
-import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { UserId } from "@bitwarden/common/types/guid";
import {
CredentialGeneratorService,
@@ -12,8 +12,6 @@ import {
Generators,
} from "@bitwarden/generator-core";
-import { completeOnAccountSwitch } from "./util";
-
/** Options group for usernames */
@Component({
selector: "tools-username-settings",
@@ -21,14 +19,12 @@ import { completeOnAccountSwitch } from "./util";
})
export class UsernameSettingsComponent implements OnInit, OnDestroy {
/** Instantiates the component
- * @param accountService queries user availability
* @param generatorService settings and policy logic
* @param formBuilder reactive form controls
*/
constructor(
private formBuilder: FormBuilder,
private generatorService: CredentialGeneratorService,
- private accountService: AccountService,
) {}
/** Binds the component to a specific user's settings.
@@ -38,6 +34,9 @@ export class UsernameSettingsComponent implements OnInit, OnDestroy {
@Input()
userId: UserId | null;
+ @Input()
+ account: Account | null = null;
+
/** Emits settings updates and completes if the settings become unavailable.
* @remarks this does not emit the initial settings. If you would like
* to receive live settings updates including the initial update,
@@ -84,10 +83,11 @@ export class UsernameSettingsComponent implements OnInit, OnDestroy {
return new BehaviorSubject(this.userId as UserId).asObservable();
}
- return this.accountService.activeAccount$.pipe(
- completeOnAccountSwitch(),
- takeUntil(this.destroyed$),
- );
+ if (this.account) {
+ return new BehaviorSubject(this.account.id as UserId).asObservable();
+ }
+
+ return new BehaviorSubject(null).asObservable();
}
private readonly destroyed$ = new Subject();
diff --git a/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.html b/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.html
index 16bccebb939..5655f1be969 100644
--- a/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.html
+++ b/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.html
@@ -1,12 +1,14 @@
diff --git a/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.ts b/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.ts
index fdde5e15d91..6dc18036029 100644
--- a/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.ts
+++ b/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.ts
@@ -4,6 +4,7 @@ import { coerceBooleanProperty } from "@angular/cdk/coercion";
import { CommonModule } from "@angular/common";
import { Component, EventEmitter, Input, Output } from "@angular/core";
+import { Account } from "@bitwarden/common/auth/abstractions/account.service";
import { GeneratorModule } from "@bitwarden/generator-components";
import { AlgorithmInfo, GeneratedCredential } from "@bitwarden/generator-core";
@@ -21,6 +22,11 @@ export class CipherFormGeneratorComponent {
@Input()
algorithm: (selected: AlgorithmInfo) => void;
+ /**
+ * The account object passed from the parent component.
+ */
+ @Input() account: Account | null = null;
+
/**
* The type of generator form to show.
*/