Skip to content

Latest commit

 

History

History

ComposeAuth

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Supabase-kt Compose Auth

Extends gotrue-kt with Native Auth composables for Compose Multiplatform

Supported targets:

Target JVM Android JS Wasm iOS
Status

Native Google Auth is only supported on Android and Native Apple Auth is only supported on iOS. Other targets or combinations rely on gotrue-kt for OAuth.

In-depth Kotlin targets

JS: Browser

Wasm: wasm-js

iOS: iosArm64, iosSimulatorArm64, iosX64

Installation

Newest version:

dependencies {
    implementation("io.github.jan-tennert.supabase:compose-auth:VERSION")
}

Install the plugin in your SupabaseClient. See the documentation for more information

val supabase = createSupabaseClient(
    supabaseUrl = "https://id.supabase.co",
    supabaseKey = "apikey"
) {
    //...
    install(Auth) {
        //your config
    }
    install(ComposeAuth) {
        googleNativeLogin(serverClientId = "google-client-id")
        appleNativeLogin()
    }
}

Native Auth Support

Currently, Compose Auth only supports Native Auth for Android with Google (via the Credential Manager) and iOS with Apple, other variations such as JS and JVM rely on fallback which by default is GoTrue-kt OAuth flow.

To learn how you can use this plugin in your compose project, visit Compose Multiplatform

Usage

The composable can be accessed trough composeAuth property from supabase

val action = supabase.composeAuth.rememberSignInWithGoogle(
    onResult = { result -> //optional error handling
        when (result) {
            is NativeSignInResult.Success -> {}
            is NativeSignInResult.ClosedByUser -> {}
            is NativeSignInResult.Error -> {}
            is NativeSignInResult.NetworkError -> {}
        }
    },
    fallback = { // optional: add custom error handling, not required by default

    }
)

Button(
    onClick = { action.startFlow() } //optional: you can also pass in extra data for the user like a name. A nonce is automatically generated, but you can also pass in a custom nonce 
) {
    Text("Google Login")
}

Native Google Auth on Android

Here is a small guide on how to use Native Google Auth on Android:

  1. Create a project in your Google Cloud Developer Console
  2. Create OAuth credentials for a Web application, and use your Supabase callback url as redirect url. (https://ID.supabase.co/auth/v1/callback)
  3. Put in the Web OAuth in your Supabase Auth Settings for Google in the Dashboard
  4. Create OAuth credentials for an Android app, and put in your package name and SHA-1 certificate (which you can get by using gradlew signingReport)
  5. Put the Android OAuth client id to the authorized client ids in the Supabase Dashboard
  6. Use the Web OAuth client id in the Compose Auth plugin