feat: wipe database on logout #25
@@ -781,7 +781,7 @@ fun BottomMenuList(
|
|||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.size(16.dp))
|
Spacer(modifier = Modifier.size(16.dp))
|
||||||
FilledTonalButton(
|
FilledTonalButton(
|
||||||
onClick = { viewModel.logout() },
|
onClick = { onDismiss { viewModel.logout() } },
|
||||||
colors = ButtonDefaults.filledTonalButtonColors(
|
colors = ButtonDefaults.filledTonalButtonColors(
|
||||||
containerColor = MaterialTheme.colorScheme.error,
|
containerColor = MaterialTheme.colorScheme.error,
|
||||||
contentColor = MaterialTheme.colorScheme.onError
|
contentColor = MaterialTheme.colorScheme.onError
|
||||||
|
|||||||
@@ -325,15 +325,34 @@ class NostrViewModel(
|
|||||||
|
|
||||||
fun logout() {
|
fun logout() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
// Reset the nostr state and wipe database
|
try {
|
||||||
nostr.signer.switch(Keys.generate())
|
_isBusy.value = true
|
||||||
nostr.prune()
|
// Reset the nostr signer and prune the database
|
||||||
// Clear credential
|
nostr.signer.switch(Keys.generate())
|
||||||
secretStore.clear("user_signer")
|
nostr.prune()
|
||||||
_signerRequired.value = true
|
} catch (e: Exception) {
|
||||||
|
showError("Logout encountered an error: ${e.message}")
|
||||||
|
} finally {
|
||||||
|
// Clear credentials from persistent storage
|
||||||
|
secretStore.clear("user_signer")
|
||||||
|
|
||||||
|
// Reset all UI states
|
||||||
|
resetInternalState()
|
||||||
|
|
||||||
|
_isBusy.value = false
|
||||||
|
_signerRequired.value = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun resetInternalState() {
|
||||||
|
_chatRooms.value = emptySet()
|
||||||
|
_contactList.value = emptySet()
|
||||||
|
_isPartialProcessedGiftWrap.value = false
|
||||||
|
_isRelayListEmpty.value = false
|
||||||
|
_isNotificationBannerDismissed.value = false
|
||||||
|
}
|
||||||
|
|
||||||
fun dismissNotificationBanner() {
|
fun dismissNotificationBanner() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
secretStore.set("notification_banner_dismissed", "true")
|
secretStore.set("notification_banner_dismissed", "true")
|
||||||
|
|||||||
Reference in New Issue
Block a user