Warning This repository is archived. Use supabase-kt instead to use Supabase in your Kotlin projects.
Kotlin JVM client for Netlify's GoTrue API.
Comes with DTOs for the responses to enable type-safe access.
Maven
<dependency>
<groupId>io.supabase</groupId>
<artifactId>gotrue-kt</artifactId>
<version>{version}</version>
<type>pom</type>
</dependency>
Gradle
implementation 'io.supabase:gotrue-kt:{version}'
val goTrueClient = GoTrueClient.defaultGoTrueClient(
url = "<base-url>",
headers = mapOf("Authorization" to "foo", "apiKey" to "bar")
)
try {
goTrueClient.invite("e@ma.il")
val updatedUser = goTrueClient.updateUser(
accessToken = "eyJ...", // read from request header
data = mapOf(
"admin" = true
)
)
println(updatedUser.updatedAt)
} catch (exc: GoTrueHttpException) {
// Exception is thrown on bad status (anything above 300)
println("Oops, status: ${exc.status}, body:\n${exc.httpBody}")
}
You can also customize the DTO for example if you turn off email verification
data class CustomGoTrueUserResponse(
val accessToken: String,
val tokenType: String,
val refreshToken: String,
val user: User
)
data class User(
val id: UUID,
val email: String,
val phone: String
)
GoTrueClient.customApacheJacksonGoTrueClient<CustomGoTrueUserResponse, GoTrueTokenResponse>(
url = "<base-url>",
headers = mapOf("Authorization" to "foo", "apiKey" to "bar")
)
If you are using supabase, the base URL will be https://<your-project-id>.supabase.co/auth/v1
The Apache Http-Client (5.x) is used for executing HTTP calls, Jackson is used to convert responses to DTOs.
If you want to change that, you need to implement the GoTrueHttpClient
and the GoTrueJsonConverter
interface.
See GoTrueHttpClientApache and GoTrueJsonConverterJackson.
GoTrueClient.goTrueClient<GoTrueUserResponse,GoTrueTokenResponse>(
goTrueHttpClient = { customHttpClient() },
goTrueJsonConverter = customConverter()
)