fix login via login screen
This commit is contained in:
parent
9c1741f769
commit
bf240c4203
1 changed files with 3 additions and 0 deletions
|
@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import eu.m724.vastapp.BuildConfig
|
||||
import eu.m724.vastapp.VastApplication
|
||||
import eu.m724.vastapp.vastai.Account
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
@ -34,12 +35,14 @@ class LoginViewModel(
|
|||
}
|
||||
|
||||
fun tryLogin() {
|
||||
application.vastApi.setApiKey(apiKey.value)
|
||||
val userDeferred = application.vastApi.getUser()
|
||||
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val user = userDeferred.await()
|
||||
application.submitKey(apiKey.value) // TODO toggle for this
|
||||
application.account = Account(user)
|
||||
_uiState.update { LoginUiState.Success(user) }
|
||||
} catch (e: Exception) {
|
||||
_uiState.update { LoginUiState.Idle }
|
||||
|
|
Loading…
Reference in a new issue