mirror of
https://github.com/bitwarden/browser
synced 2025-12-23 11:43:46 +00:00
* refactor: introduce @bitwarden/serialization * refactor: introduce @bitwarden/guid * refactor: introduce @bitwaren/client-type * refactor: introduce @bitwarden/core-test-utils * refactor: introduce @bitwarden/state and @bitwarden/state-test-utils Creates initial project structure for centralized application state management. Part of modularization effort to extract state code from common. * Added state provider documentation to README. * Changed callouts to Github format. * Fixed linting on file name. * Forced git to accept rename --------- Co-authored-by: Todd Martin <tmartin@bitwarden.com>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
|
|
import { IRREVERSIBLE, Migrator } from "../migrator";
|
|
|
|
type ExpectedAccountType = NonNullable<unknown>;
|
|
|
|
export const REFRESH_TOKEN_MIGRATED_TO_SECURE_STORAGE: KeyDefinitionLike = {
|
|
key: "refreshTokenMigratedToSecureStorage", // matches KeyDefinition.key
|
|
stateDefinition: {
|
|
name: "token", // matches StateDefinition.name in StateDefinitions
|
|
},
|
|
};
|
|
|
|
export class RemoveRefreshTokenMigratedFlagMigrator extends Migrator<57, 58> {
|
|
async migrate(helper: MigrationHelper): Promise<void> {
|
|
const accounts = await helper.getAccounts<ExpectedAccountType>();
|
|
async function migrateAccount(userId: string, account: ExpectedAccountType): Promise<void> {
|
|
const refreshTokenMigratedFlag = await helper.getFromUser(
|
|
userId,
|
|
REFRESH_TOKEN_MIGRATED_TO_SECURE_STORAGE,
|
|
);
|
|
|
|
if (refreshTokenMigratedFlag != null) {
|
|
// Only delete the flag if it exists
|
|
await helper.removeFromUser(userId, REFRESH_TOKEN_MIGRATED_TO_SECURE_STORAGE);
|
|
}
|
|
}
|
|
|
|
await Promise.all([...accounts.map(({ userId, account }) => migrateAccount(userId, account))]);
|
|
}
|
|
|
|
async rollback(helper: MigrationHelper): Promise<void> {
|
|
throw IRREVERSIBLE;
|
|
}
|
|
}
|