-
I'm using a separate file (under :app module but separate from Android with import com.russhwolf.settings.MapSettings
import io.github.jan.supabase.auth.Auth
import io.github.jan.supabase.auth.SettingsSessionManager
import io.github.jan.supabase.auth.auth
import io.github.jan.supabase.auth.providers.builtin.Email
import io.github.jan.supabase.createSupabaseClient
import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.postgrest.PropertyConversionMethod
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.buildJsonObject
fun main() {
val supabaseClient = createSupabaseClient(
supabaseUrl = BuildConfig.SUPABASE_URL,
supabaseKey = BuildConfig.SUPABASE_KEY
) {
install(Postgrest) {
propertyConversionMethod = PropertyConversionMethod.SERIAL_NAME
}
install(Auth) {
sessionManager = SettingsSessionManager(MapSettings())
}
}
// ...
} However, the code throws an error:
Clicking on the link provided in the error redirects me to the main GitHub page, and other than the issue page mentioned above I can't find any other mention of this online. Is there a way to fix this? Using:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I found the solution! The problem was within the However, Here's the fixed code: import android.content.Context
import com.russhwolf.settings.SettingsInitializer
import io.github.jan.supabase.auth.Auth
import io.github.jan.supabase.auth.auth
import io.github.jan.supabase.auth.providers.builtin.Email
import io.github.jan.supabase.createSupabaseClient
import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.postgrest.PropertyConversionMethod
import io.mockk.mockk
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.setMain
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.buildJsonObject
@OptIn(ExperimentalCoroutinesApi::class)
fun main() {
val context: Context = mockk(relaxed = true)
SettingsInitializer().create(context)
Dispatchers.setMain(Dispatchers.IO)
val supabaseClient = createSupabaseClient(
supabaseUrl = BuildConfig.SUPABASE_URL,
supabaseKey = BuildConfig.SUPABASE_KEY
) {
install(Postgrest) {
propertyConversionMethod = PropertyConversionMethod.SERIAL_NAME
}
install(Auth)
}
// ...
} Thanks! |
Beta Was this translation helpful? Give feedback.
I found the solution! The problem was within the
Settings()
factory function ofcom.russhwolf.settings.Settings
. This function gets called increateDefaultSettings()
to be assigned by default tosessionManager
when installing the Auth module.However,
Settings()
needs to invoke theSharedPreferences
API on Android, which isn't possible because this is a native Kotlin test, as stated by russhwolf here. To fix it, I have to mock the Context class first then initialize theSettings
with the mocked context. Also, I have to manually set the Dispatcher since it would be used later on.Here's the fixed code: