fix login via login screen

This commit is contained in:
Minecon724 2024-08-08 13:14:29 +02:00
parent 9c1741f769
commit bf240c4203
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import eu.m724.vastapp.BuildConfig import eu.m724.vastapp.BuildConfig
import eu.m724.vastapp.VastApplication import eu.m724.vastapp.VastApplication
import eu.m724.vastapp.vastai.Account
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
@ -34,12 +35,14 @@ class LoginViewModel(
} }
fun tryLogin() { fun tryLogin() {
application.vastApi.setApiKey(apiKey.value)
val userDeferred = application.vastApi.getUser() val userDeferred = application.vastApi.getUser()
viewModelScope.launch { viewModelScope.launch {
try { try {
val user = userDeferred.await() val user = userDeferred.await()
application.submitKey(apiKey.value) // TODO toggle for this application.submitKey(apiKey.value) // TODO toggle for this
application.account = Account(user)
_uiState.update { LoginUiState.Success(user) } _uiState.update { LoginUiState.Success(user) }
} catch (e: Exception) { } catch (e: Exception) {
_uiState.update { LoginUiState.Idle } _uiState.update { LoginUiState.Idle }