mirror of
https://github.com/bitwarden/android.git
synced 2026-08-01 18:53:39 -05:00
Lock vault and clear data when logging out (#288)
This commit is contained in:
committed by
Álison Fernandes
parent
de6f707964
commit
e41e681700
@@ -202,6 +202,7 @@ class AuthRepositoryImpl constructor(
|
||||
|
||||
override fun logout(userId: String) {
|
||||
val currentUserState = authDiskSource.userState ?: return
|
||||
val wasActiveUser = userId == activeUserId
|
||||
|
||||
// Remove the active user from the accounts map
|
||||
val updatedAccounts = currentUserState
|
||||
@@ -228,6 +229,12 @@ class AuthRepositoryImpl constructor(
|
||||
// Update the user information and log out
|
||||
authDiskSource.userState = null
|
||||
}
|
||||
|
||||
// Lock the vault for the logged out user
|
||||
vaultRepository.lockVaultIfNecessary(userId)
|
||||
|
||||
// Clear the current vault data if the logged out user was the active one.
|
||||
if (wasActiveUser) vaultRepository.clearUnlockedData()
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount", "LongMethod")
|
||||
|
||||
@@ -52,6 +52,11 @@ interface VaultRepository {
|
||||
*/
|
||||
fun getVaultFolderStateFlow(folderId: String): StateFlow<DataState<FolderView?>>
|
||||
|
||||
/**
|
||||
* Locks the vault for the user with the given [userId] if necessary.
|
||||
*/
|
||||
fun lockVaultIfNecessary(userId: String)
|
||||
|
||||
/**
|
||||
* Attempt to unlock the vault and sync the vault data for the currently active user.
|
||||
*/
|
||||
|
||||
@@ -155,6 +155,10 @@ class VaultRepositoryImpl constructor(
|
||||
initialValue = DataState.Loading,
|
||||
)
|
||||
|
||||
override fun lockVaultIfNecessary(userId: String) {
|
||||
setVaultToLocked(userId = userId)
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override suspend fun unlockVaultAndSyncForCurrentUser(
|
||||
masterPassword: String,
|
||||
@@ -233,6 +237,16 @@ class VaultRepositoryImpl constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This is temporary. Eventually this needs to be based on the presence of various
|
||||
// user keys but this will likely require SDK updates to support this (BIT-1190).
|
||||
private fun setVaultToLocked(userId: String) {
|
||||
vaultMutableStateFlow.update {
|
||||
it.copy(
|
||||
unlockedVaultUserIds = it.unlockedVaultUserIds - userId,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun storeUserKeyAndPrivateKey(
|
||||
userKey: String?,
|
||||
privateKey: String?,
|
||||
|
||||
Reference in New Issue
Block a user