feat: wipe database on logout (#25)

Reviewed-on: #25
This commit was merged in pull request #25.
This commit is contained in:
2026-06-25 08:12:27 +00:00
parent 750d46bc9e
commit 010a8b4060
3 changed files with 36 additions and 6 deletions

View File

@@ -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

View File

@@ -188,6 +188,14 @@ class Nostr {
} }
} }
suspend fun prune() {
try {
client?.database()?.wipe()
} catch (e: Exception) {
throw IllegalStateException("Failed to prune database: ${e.message}", e)
}
}
suspend fun setSigner(new: AsyncNostrSigner) { suspend fun setSigner(new: AsyncNostrSigner) {
try { try {
signer.switch(new) signer.switch(new)
@@ -994,7 +1002,7 @@ class Nostr {
try { try {
val currentUser = val currentUser =
signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in") signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in")
val kind = Kind.fromStd(KindStandard.CONTACT_LIST) val kind = Kind.fromStd(KindStandard.CONTACT_LIST)
val filter = Filter().kind(kind).author(currentUser).limit(1u) val filter = Filter().kind(kind).author(currentUser).limit(1u)

View File

@@ -325,12 +325,34 @@ class NostrViewModel(
fun logout() { fun logout() {
viewModelScope.launch { viewModelScope.launch {
secretStore.clear("user_signer") try {
nostr.signer.switch(Keys.generate()) _isBusy.value = true
_signerRequired.value = true // Reset the nostr signer and prune the database
nostr.signer.switch(Keys.generate())
nostr.prune()
} 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")
@@ -821,7 +843,7 @@ class NostrViewModel(
} }
return emptyList() return emptyList()
} }
suspend fun verifyActivity(pubkey: PublicKey): Timestamp? { suspend fun verifyActivity(pubkey: PublicKey): Timestamp? {
return try { return try {
nostr.verifyActivity(pubkey) nostr.verifyActivity(pubkey)