Skip to content

Latest commit

 

History

History
147 lines (112 loc) · 5.5 KB

File metadata and controls

147 lines (112 loc) · 5.5 KB

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 iOS* and Native Apple Auth is only supported on iOS. Other targets or combinations rely on auth-kt for OAuth.
* starting with version 3.3.0

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 -> {}
        }
    },
    onIdToken = ComposeAuth.LINK_IDENTITY_CALLBACK, // optional: if you want to link an identity to an existing account rather than signing in
    fallback = { // optional: override custom fallback 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")
}

You can also provide a custom onIdToken value, if you want to handle the signing-in yourself.

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

Native Google Auth on iOS

Before start, make sure your iOS app works well first, it would be easier to isolate the issue from this step to resolve

  1. Create a project in your Google Cloud Developer Console
  2. Create OAuth credentials for a Web application, iOS version
  3. Put in Client ID of Web OAuth, Apple OAuth in your Supabase Auth Settings for Google in the Dashboard
  4. Set up XCode 26 Add Client ID and Reversed Client ID (Retrieved from iOS OAuth details on Google Console). Your Info.plist will look like this:
<dict>
	<key>CFBundleIdentifier</key>
	<string>io.github.jan.supabase.ios</string>
	<key>GIDClientID</key>
	<string>YOUR_CLIENT_ID</string>
	<key>CADisableMinimumFrameDurationOnPhone</key>
	<true/>
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>YOUR_REVERSED_CLIENT_ID</string>
			</array>
		</dict>
	</array>
</dict>
  1. Download exportedNativeBridge at /ComposeAuth/exportedNativeBridge in this repository In XCode, add it as dependency Step 1: Right click on the left tool bar > Select Add dependencies Screenshot 2025-11-01 at 00 38 41

    Step 2: From opened dialog > Add local Screenshot 2025-10-30 at 21 10 28

    Step 3: Continue Add package

    Screenshot 2025-11-01 at 00 38 51

    Step 4: Add GoogleSignIn 9.0.0 or the one compatible with your project as below: Screenshot 2025-11-02 at 20 51 45

  2. Build your app. It should work now.