diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt index e4901ed3ab..8faf6d279d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt @@ -72,6 +72,8 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated } override fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback): Cancelable { + pendingSessionData = null + return GlobalScope.launch(coroutineDispatchers.main) { pendingSessionStore.delete() @@ -153,25 +155,28 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated currentLoginWizard = null currentRegistrationWizard = null - GlobalScope.launch(coroutineDispatchers.main) { - // Keep only the home sever config - pendingSessionData?.homeServerConnectionConfig - ?.let { - pendingSessionData = PendingSessionData(it) - .also { data -> pendingSessionStore.savePendingSessionData(data) } + // Keep only the home sever config + // Update the local pendingSessionData synchronously + pendingSessionData = pendingSessionData?.homeServerConnectionConfig + ?.let { PendingSessionData(it) } + .also { + GlobalScope.launch(coroutineDispatchers.main) { + if (it == null) { + // Should not happen + pendingSessionStore.delete() + } else { + pendingSessionStore.savePendingSessionData(it) + } } - ?: run { - // Should not happen - pendingSessionData = null - pendingSessionStore.delete() - } - } + } } override fun reset() { currentLoginWizard = null currentRegistrationWizard = null + pendingSessionData = null + GlobalScope.launch(coroutineDispatchers.main) { pendingSessionStore.delete() }