1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +01: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
No known key found for this signature in database
GPG Key ID: E70B5FFC81DFEC1A
5 changed files with 24 additions and 14 deletions

View File

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

View File

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

View File

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

View File

@ -105,7 +105,9 @@ export class KnownAccountsMigrator extends Migrator<59, 60> {
private async migrateActiveAccountId(helper: MigrationHelper) {
const activeAccountId = await helper.get<string>("activeUserId");
await helper.setToGlobal(ACCOUNT_ACTIVE_ACCOUNT_ID, activeAccountId);
await helper.remove("activeUserId");
if (activeAccountId != null) {
await helper.setToGlobal(ACCOUNT_ACTIVE_ACCOUNT_ID, activeAccountId);
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))]);
// Delete global data (works for browser extension and web; CLI doesn't have these as global settings).
delete globalData?.vaultTimeout;
delete globalData?.vaultTimeoutAction;
await helper.set("global", globalData);
if (globalData != null) {
// Delete global data (works for browser extension and web; CLI doesn't have these as global settings).
delete globalData?.vaultTimeout;
delete globalData?.vaultTimeoutAction;
await helper.set("global", globalData);
}
// 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.