Skip to main content
This guide is for our new Kotlin Multiplatform SDK which is in Public beta. If you are instead looking for the stable version, please see stytch-android and the usage docs here.
For a full walk-through of how to get up and running with a sign-up and login flow using Stytch, check out our Quickstart Guide.
1

Add the dependency

Add the Stytch B2B SDK to your build.gradle.kts:
dependencies {
    implementation("com.stytch.sdk:b2b-headless:VERSION")
}
The SDK is published to Maven Central. Make sure mavenCentral() is in your repository list.
2

Configure deep link handling

To handle magic links, register a custom URL scheme in your AndroidManifest.xml:
<activity android:name=".MainActivity" ...>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="your-app-scheme" />
    </intent-filter>
</activity>
Pass this scheme as the loginRedirectUrl and signupRedirectUrl when starting magic link flows.
3

Create the Stytch client

Initialize the Stytch client with your Project’s public_token from the Project Overview of the Stytch Dashboard.
import com.stytch.sdk.b2b.createStytchB2B
import com.stytch.sdk.data.StytchClientConfiguration

val configuration = StytchClientConfiguration(
    context = applicationContext,
    publicToken = "public-token-test-1234"
)
val stytch = createStytchB2B(configuration)
The client is a singleton — subsequent calls to createStytchB2B with the same process return the same instance.
4

Observe authentication state

Subscribe to authenticationStateFlow to react to sign-in and sign-out events:
lifecycleScope.launch {
    stytch.authenticationStateFlow.collect { state ->
        // state is B2BAuthenticationState.Authenticated, Unauthenticated, or Loading
    }
}