1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 06:13:38 +00:00

feat: fix all migrations that were setting undefined values

This commit is contained in:
Andreas Coroiu
2024-07-02 15:45:41 +02:00
parent 34f0f7d922
commit 034713256c
5 changed files with 24 additions and 14 deletions

View File

@@ -47,11 +47,13 @@ export class MoveEnvironmentStateToProviders extends Migrator<11, 12> {
}), }),
); );
if (legacyGlobal != null) {
// Delete legacy global data // Delete legacy global data
delete legacyGlobal?.region; delete legacyGlobal?.region;
delete legacyGlobal?.environmentUrls; delete legacyGlobal?.environmentUrls;
await helper.set("global", legacyGlobal); await helper.set("global", legacyGlobal);
} }
}
async rollback(helper: MigrationHelper): Promise<void> { async rollback(helper: MigrationHelper): Promise<void> {
let legacyGlobal = await helper.get<ExpectedGlobalType>("global"); let legacyGlobal = await helper.get<ExpectedGlobalType>("global");

View File

@@ -143,9 +143,11 @@ export class TokenServiceStateProviderMigrator extends Migrator<37, 38> {
await helper.setToGlobal(EMAIL_TWO_FACTOR_TOKEN_RECORD_DISK_LOCAL, emailTwoFactorTokenRecord); await helper.setToGlobal(EMAIL_TWO_FACTOR_TOKEN_RECORD_DISK_LOCAL, emailTwoFactorTokenRecord);
// Delete global data // Delete global data
if (globalData != null) {
delete globalData?.twoFactorToken; delete globalData?.twoFactorToken;
await helper.set("global", globalData); await helper.set("global", globalData);
} }
}
async rollback(helper: MigrationHelper): Promise<void> { async rollback(helper: MigrationHelper): Promise<void> {
const accounts = await helper.getAccounts<ExpectedAccountType>(); const accounts = await helper.getAccounts<ExpectedAccountType>();

View File

@@ -20,9 +20,11 @@ export class RememberedEmailMigrator extends Migrator<50, 51> {
} }
// Delete legacy global data // Delete legacy global data
if (legacyGlobal != null) {
delete legacyGlobal?.rememberedEmail; delete legacyGlobal?.rememberedEmail;
await helper.set("global", legacyGlobal); await helper.set("global", legacyGlobal);
} }
}
async rollback(helper: MigrationHelper): Promise<void> { async rollback(helper: MigrationHelper): Promise<void> {
let legacyGlobal = await helper.get<ExpectedGlobalState>("global"); let legacyGlobal = await helper.get<ExpectedGlobalState>("global");

View File

@@ -105,7 +105,9 @@ export class KnownAccountsMigrator extends Migrator<59, 60> {
private async migrateActiveAccountId(helper: MigrationHelper) { private async migrateActiveAccountId(helper: MigrationHelper) {
const activeAccountId = await helper.get<string>("activeUserId"); const activeAccountId = await helper.get<string>("activeUserId");
if (activeAccountId != null) {
await helper.setToGlobal(ACCOUNT_ACTIVE_ACCOUNT_ID, activeAccountId); await helper.setToGlobal(ACCOUNT_ACTIVE_ACCOUNT_ID, activeAccountId);
await helper.remove("activeUserId"); await helper.remove("activeUserId");
} }
} }
}

View File

@@ -122,10 +122,12 @@ export class VaultTimeoutSettingsServiceStateProviderMigrator extends Migrator<6
await Promise.all([...accounts.map(({ userId, account }) => migrateAccount(userId, account))]); await Promise.all([...accounts.map(({ userId, account }) => migrateAccount(userId, account))]);
if (globalData != null) {
// Delete global data (works for browser extension and web; CLI doesn't have these as global settings). // Delete global data (works for browser extension and web; CLI doesn't have these as global settings).
delete globalData?.vaultTimeout; delete globalData?.vaultTimeout;
delete globalData?.vaultTimeoutAction; delete globalData?.vaultTimeoutAction;
await helper.set("global", globalData); await helper.set("global", globalData);
}
// Remove desktop only settings. These aren't found by the above global key removal b/c of // Remove desktop only settings. These aren't found by the above global key removal b/c of
// the different storage key format. This removal does not cause any issues on migrating for other clients. // the different storage key format. This removal does not cause any issues on migrating for other clients.