1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 19:23:52 +00:00
Files
browser/libs/common/src/state-migrations/migrations/28-move-biometric-unlock-to-state-providers.ts
Matt Gibson b691b6b1d6 [PM-6484] Revert "[PM-5277] Migrate Sync Service to State Provider (#7680)" (#8157)
* Revert "[PM-5277] Migrate Sync Service to State Provider (#7680)"

This reverts commit 78008a9e1e.

Includes a noop migration builder that allows us to bridge over the deleted migration

* Prefer revert migrations to noop

this revert avoids the need to change behavior between released vs unreleased migrations and keeps some dangerous code out of the repo :success:

* Update ordering of badge settings migrator to be consistent with `rc`, which was cut with only up to version 25

* Fix missing type import
2024-03-04 09:34:22 -05:00

59 lines
1.8 KiB
TypeScript

import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
import { Migrator } from "../migrator";
type ExpectedAccountType = {
settings?: {
biometricUnlock?: boolean;
};
};
export const BIOMETRIC_UNLOCK_ENABLED: KeyDefinitionLike = {
key: "biometricUnlockEnabled",
stateDefinition: { name: "biometricSettings" },
};
export class MoveBiometricUnlockToStateProviders extends Migrator<27, 28> {
async migrate(helper: MigrationHelper): Promise<void> {
const legacyAccounts = await helper.getAccounts<ExpectedAccountType>();
await Promise.all(
legacyAccounts.map(async ({ userId, account }) => {
if (account == null) {
return;
}
// Move account data
if (account?.settings?.biometricUnlock != null) {
await helper.setToUser(
userId,
BIOMETRIC_UNLOCK_ENABLED,
account.settings.biometricUnlock,
);
}
// Delete old account data
delete account?.settings?.biometricUnlock;
await helper.set(userId, account);
}),
);
}
async rollback(helper: MigrationHelper): Promise<void> {
async function rollbackUser(userId: string, account: ExpectedAccountType) {
const biometricUnlock = await helper.getFromUser<boolean>(userId, BIOMETRIC_UNLOCK_ENABLED);
if (biometricUnlock != null) {
account ??= {};
account.settings ??= {};
account.settings.biometricUnlock = biometricUnlock;
await helper.setToUser(userId, BIOMETRIC_UNLOCK_ENABLED, null);
await helper.set(userId, account);
}
}
const accounts = await helper.getAccounts<ExpectedAccountType>();
await Promise.all(accounts.map(({ userId, account }) => rollbackUser(userId, account)));
}
}