Skip to content

Commit 2da3269

Browse files
committed
fix: preserve pubky session
1 parent 263a297 commit 2da3269

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

app/src/main/java/to/bitkit/repositories/PubkyRepo.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ class PubkyRepo @Inject constructor(
206206
): InitResult = withContext(ioDispatcher) {
207207
if (storedSecretKeyHex.isNullOrEmpty()) {
208208
if (!savedSessionSecret.isNullOrEmpty()) {
209-
Logger.warn("Skipped re-sign-in recovery, no secret key available", context = TAG)
210-
runCatching { keychain.delete(Keychain.Key.PAYKIT_SESSION.name) }
211-
notifyBackupStateChanged()
209+
Logger.warn("Skipped re-sign-in recovery, keeping saved session", context = TAG)
212210
InitResult.RestorationFailed
213211
} else {
214212
InitResult.NoSession
@@ -223,8 +221,6 @@ class PubkyRepo @Inject constructor(
223221
InitResult.Restored(publicKey)
224222
}.getOrElse {
225223
Logger.error("Failed re-sign-in recovery", it, context = TAG)
226-
runCatching { keychain.delete(Keychain.Key.PAYKIT_SESSION.name) }
227-
notifyBackupStateChanged()
228224
InitResult.RestorationFailed
229225
}
230226
}

app/src/test/java/to/bitkit/repositories/PubkyRepoTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class PubkyRepoTest : BaseUnitTest() {
465465
}
466466

467467
@Test
468-
fun `initialize should delete stale saved session when re-sign-in is unavailable`() = test {
468+
fun `initialize should keep saved session when re-sign-in is unavailable`() = test {
469469
val session = "stale_session"
470470
whenever(keychain.loadString(Keychain.Key.PAYKIT_SESSION.name)).thenReturn(session)
471471
whenever(keychain.loadString(Keychain.Key.PUBKY_SECRET_KEY.name)).thenReturn(null)
@@ -475,7 +475,7 @@ class PubkyRepoTest : BaseUnitTest() {
475475

476476
assertTrue(sut.sessionRestorationFailed.value)
477477
assertFalse(sut.isAuthenticated.value)
478-
verifyBlocking(keychain) { delete(Keychain.Key.PAYKIT_SESSION.name) }
478+
verifyBlocking(keychain, never()) { delete(Keychain.Key.PAYKIT_SESSION.name) }
479479
}
480480

481481
@Test

0 commit comments

Comments
 (0)