Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Login screen crashes when we fill wrong login details #2288

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package com.mifos.core.domain.useCases
import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.LoginRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import org.openapitools.client.models.PostAuthenticationResponse

Expand All @@ -25,12 +26,10 @@ class LoginUseCase(private val loginRepository: LoginRepository) {
username: String,
password: String,
): Flow<Resource<PostAuthenticationResponse>> = flow {
try {
emit(Resource.Loading())
val result = loginRepository.login(username, password)
emit(Resource.Success(result))
} catch (e: Exception) {
emit(Resource.Error(e.message.toString()))
}
emit(Resource.Loading())
val result = loginRepository.login(username, password)
emit(Resource.Success(result))
}.catch { e ->
emit(Resource.Error(e.message.toString()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Network
import com.mifos.core.common.utils.Resource
import com.mifos.core.datastore.PrefManager
import com.mifos.core.domain.useCases.LoginUseCase
import com.mifos.core.domain.useCases.PasswordValidationUseCase
import com.mifos.core.domain.useCases.UsernameValidationUseCase
import com.mifos.core.model.getInstanceUrl
Expand All @@ -41,7 +42,7 @@ class LoginViewModel @Inject constructor(
private val usernameValidationUseCase: UsernameValidationUseCase,
private val passwordValidationUseCase: PasswordValidationUseCase,
private val baseApiManager: BaseApiManager,
private val loginUseCase: com.mifos.core.domain.useCases.LoginUseCase,
private val loginUseCase: LoginUseCase,
) :
ViewModel() {

Expand Down Expand Up @@ -99,7 +100,12 @@ class LoginViewModel @Inject constructor(
}

is Resource.Success -> {
result.data?.let { onLoginSuccessful(it, username, password) }
if (result.data?.authenticated == true && result.data != null) {
onLoginSuccessful(result.data!!, username, password)
} else {
_loginUiState.value =
LoginUiState.ShowError(R.string.feature_auth_error_login_failed)
}
}
}
}
Expand Down
Loading