1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-26 17:08:33 +01:00

Use getAccount when scaffolding + pass in the correct userId (#676)

This commit is contained in:
Addison Beck 2022-02-11 12:45:48 -05:00 committed by GitHub
parent cdc6cbaeb3
commit 3a1b5bf9a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2227,9 +2227,11 @@ export class StateService<
// TODO: There is a tech debt item for splitting up these methods - only Web uses multiple storage locations in its storageService. // TODO: There is a tech debt item for splitting up these methods - only Web uses multiple storage locations in its storageService.
// For now these methods exist with some redundancy to facilitate this special web requirement. // For now these methods exist with some redundancy to facilitate this special web requirement.
protected async scaffoldNewAccountLocalStorage(account: TAccount): Promise<void> { protected async scaffoldNewAccountLocalStorage(account: TAccount): Promise<void> {
const storedAccount = await this.storageService.get<TAccount>( const storedAccount = await this.getAccount(
account.profile.userId, this.reconcileOptions(
{ userId: account.profile.userId },
await this.defaultOnDiskLocalOptions() await this.defaultOnDiskLocalOptions()
)
); );
// EnvironmentUrls are set before authenticating and should override whatever is stored from any previous session // EnvironmentUrls are set before authenticating and should override whatever is stored from any previous session
const environmentUrls = account.settings.environmentUrls; const environmentUrls = account.settings.environmentUrls;
@ -2246,31 +2248,57 @@ export class StateService<
account.profile.apiKeyClientId = null; account.profile.apiKeyClientId = null;
account.keys.apiKeyClientSecret = null; account.keys.apiKeyClientSecret = null;
} }
await this.saveAccount(account, await this.defaultOnDiskLocalOptions()); await this.saveAccount(
account,
this.reconcileOptions(
{ userId: account.profile.userId },
await this.defaultOnDiskLocalOptions()
)
);
} }
protected async scaffoldNewAccountMemoryStorage(account: TAccount): Promise<void> { protected async scaffoldNewAccountMemoryStorage(account: TAccount): Promise<void> {
const storedAccount = await this.storageService.get<TAccount>( const storedAccount = await this.getAccount(
account.profile.userId, this.reconcileOptions(
{ userId: account.profile.userId },
await this.defaultOnDiskMemoryOptions() await this.defaultOnDiskMemoryOptions()
)
); );
if (storedAccount?.settings != null) { if (storedAccount?.settings != null) {
storedAccount.settings.environmentUrls = account.settings.environmentUrls; storedAccount.settings.environmentUrls = account.settings.environmentUrls;
account.settings = storedAccount.settings; account.settings = storedAccount.settings;
} }
await this.saveAccount(account, await this.defaultOnDiskLocalOptions()); await this.storageService.save(
account.profile.userId,
account,
await this.defaultOnDiskMemoryOptions()
);
await this.saveAccount(
account,
this.reconcileOptions(
{ userId: account.profile.userId },
await this.defaultOnDiskMemoryOptions()
)
);
} }
protected async scaffoldNewAccountSessionStorage(account: TAccount): Promise<void> { protected async scaffoldNewAccountSessionStorage(account: TAccount): Promise<void> {
const storedAccount = await this.storageService.get<TAccount>( const storedAccount = await this.getAccount(
account.profile.userId, this.reconcileOptions({ userId: account.profile.userId }, await this.defaultOnDiskOptions())
await this.defaultOnDiskOptions()
); );
if (storedAccount?.settings != null) { if (storedAccount?.settings != null) {
storedAccount.settings.environmentUrls = account.settings.environmentUrls; storedAccount.settings.environmentUrls = account.settings.environmentUrls;
account.settings = storedAccount.settings; account.settings = storedAccount.settings;
} }
await this.saveAccount(account, await this.defaultOnDiskLocalOptions()); await this.storageService.save(
account.profile.userId,
account,
await this.defaultOnDiskMemoryOptions()
);
await this.saveAccount(
account,
this.reconcileOptions({ userId: account.profile.userId }, await this.defaultOnDiskOptions())
);
} }
// //