mirror of
https://github.com/bitwarden/android.git
synced 2026-06-04 19:56:39 -05:00
VaultRepo clears in-memory vault data whenever the active account changes (#1010)
This commit is contained in:
committed by
Álison Fernandes
parent
5928987a9b
commit
8cc25a57f0
@@ -469,7 +469,6 @@ class AuthRepositoryImpl(
|
||||
|
||||
// Attempt to unlock the vault with password if possible.
|
||||
password?.let {
|
||||
vaultRepository.clearUnlockedData()
|
||||
vaultRepository.unlockVault(
|
||||
userId = userStateJson.activeUserId,
|
||||
email = userStateJson.activeAccount.profile.email,
|
||||
@@ -504,7 +503,6 @@ class AuthRepositoryImpl(
|
||||
|
||||
// Attempt to unlock the vault with auth request if possible.
|
||||
deviceData?.let { model ->
|
||||
vaultRepository.clearUnlockedData()
|
||||
vaultRepository.unlockVault(
|
||||
userId = userStateJson.activeUserId,
|
||||
email = userStateJson.activeAccount.profile.email,
|
||||
@@ -582,12 +580,7 @@ class AuthRepositoryImpl(
|
||||
}
|
||||
|
||||
override fun logout(userId: String) {
|
||||
val wasActiveUser = userId == activeUserId
|
||||
|
||||
userLogoutManager.logout(userId = userId)
|
||||
|
||||
// Clear the current vault data if the logged out user was the active one.
|
||||
if (wasActiveUser) vaultRepository.clearUnlockedData()
|
||||
}
|
||||
|
||||
override suspend fun resendVerificationCodeEmail(): ResendEmailResult =
|
||||
@@ -618,9 +611,6 @@ class AuthRepositoryImpl(
|
||||
// Switch to the new user
|
||||
authDiskSource.userState = currentUserState.copy(activeUserId = userId)
|
||||
|
||||
// Clear data for the previous user
|
||||
vaultRepository.clearUnlockedData()
|
||||
|
||||
// Clear any pending account additions
|
||||
hasPendingAccountAddition = false
|
||||
|
||||
|
||||
@@ -100,11 +100,6 @@ interface VaultRepository : VaultLockManager {
|
||||
*/
|
||||
val totpCodeFlow: Flow<TotpCodeResult>
|
||||
|
||||
/**
|
||||
* Clear any previously unlocked, in-memory data (vault, send, etc).
|
||||
*/
|
||||
fun clearUnlockedData()
|
||||
|
||||
/**
|
||||
* Completely remove any persisted data from the vault.
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.bitwarden.crypto.Kdf
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.toSdkParams
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.toUpdatedUserStateJson
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.userSwitchingChangesFlow
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.util.isNoConnectionError
|
||||
import com.x8bit.bitwarden.data.platform.manager.PushManager
|
||||
@@ -215,6 +216,14 @@ class VaultRepositoryImpl(
|
||||
get() = mutableSendDataStateFlow.asStateFlow()
|
||||
|
||||
init {
|
||||
authDiskSource
|
||||
.userSwitchingChangesFlow
|
||||
.onEach {
|
||||
syncJob.cancel()
|
||||
clearUnlockedData()
|
||||
}
|
||||
.launchIn(unconfinedScope)
|
||||
|
||||
// Setup ciphers MutableStateFlow
|
||||
mutableCiphersStateFlow
|
||||
.observeWhenSubscribedAndLoggedIn(authDiskSource.userStateFlow) { activeUserId ->
|
||||
@@ -282,7 +291,7 @@ class VaultRepositoryImpl(
|
||||
.launchIn(ioScope)
|
||||
}
|
||||
|
||||
override fun clearUnlockedData() {
|
||||
private fun clearUnlockedData() {
|
||||
mutableCiphersStateFlow.update { DataState.Loading }
|
||||
mutableDomainsStateFlow.update { DataState.Loading }
|
||||
mutableFoldersStateFlow.update { DataState.Loading }
|
||||
|
||||
Reference in New Issue
Block a user