1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 10:13:31 +00:00

refactor(auth-state-updates): [Auth/PM-18544] Add shouldUpdate() checks to frequently updated state (#15994)

Adds `shouldUpdate()` checks to frequently updated disk state in the Auth domain, specifically:
- `account_verifyNewDeviceLogin`
- `token_accessToken`
- `token_refreshToken`
- `masterPassword_masterKeyHash`
This ensures that the state only updates if the new value is different from the previous value, thus avoiding unnecessary updates.
This commit is contained in:
rr-bw
2025-08-18 13:09:41 -07:00
committed by GitHub
parent 827c4c0301
commit 581e64b8f7
4 changed files with 43 additions and 14 deletions

View File

@@ -149,14 +149,18 @@ export class MasterPasswordService implements InternalMasterPasswordServiceAbstr
if (userId == null) {
throw new Error("User ID is required.");
}
await this.stateProvider.getUser(userId, MASTER_KEY_HASH).update((_) => masterKeyHash);
await this.stateProvider.getUser(userId, MASTER_KEY_HASH).update((_) => masterKeyHash, {
shouldUpdate: (previousValue) => previousValue !== masterKeyHash,
});
}
async clearMasterKeyHash(userId: UserId): Promise<void> {
if (userId == null) {
throw new Error("User ID is required.");
}
await this.stateProvider.getUser(userId, MASTER_KEY_HASH).update((_) => null);
await this.stateProvider.getUser(userId, MASTER_KEY_HASH).update((_) => null, {
shouldUpdate: (previousValue) => previousValue !== null,
});
}
async setMasterKeyEncryptedUserKey(encryptedKey: EncString, userId: UserId): Promise<void> {