Код: Выделить всё
024-10-16 15:34:52.847 18432-18432 AuthViewModel com.logomo.logomo E Error fetching API key: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType package com.logomo.logomo.data.login.
Код: Выделить всё
private suspend fun loginAndGetApiKey(uid: String) {
try {
_isLoading.value = true
logInResponse = logInRepository.signInUser(uid)
// Suspends here until API call finishes
logInResponse?.let {
_apiKey.value = it.api_key
Log.d(TAG, "getApiKey: ${it.status}")
Log.d(TAG, "getApiKey: ${apiKey.value}")
// Save the API key and retrieve it safely
apiKey.value?.let { it1 -> saveApiKey(apiKey = it1) }
val savedApiKey = getApiKey()
Log.d(TAG, "getApiKeyFunc: $savedApiKey")
} ?: run {
Log.e(TAG, "Login response is null, failed to retrieve API key")
}
} catch (e: Exception) {
signOut()
Log.e(TAG, "Error fetching API key: ${e.message}")
} finally {
_isLoading.value = false
}
}
Код: Выделить всё
//This is the ApiService class
import com.logomo.logomo.retrofit.SignInUserData
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST
interface LogInApiService {
@FormUrlEncoded
@POST("users/user_login.php")
suspend fun signInUser(
@Field("uid") uid: String,
): SignInUserData
}
Код: Выделить всё
//This is the Repository class
import com.logomo.logomo.retrofit.SignInUserData
import javax.inject.Singleton
@Singleton
class NetworkLogInRepository(
private val logInApiService: LogInApiService
) {
suspend fun signInUser(uid: String): SignInUserData {
return logInApiService.signInUser(uid)
}
}
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/790 ... but-not-in