Skip to main content

sdk.auth.email

sendOTP

Send a one-time password to a user’s email address.
suspend fun sendOTP(email: String)

Parameters

  • email (String) - User’s email address

Example

viewModelScope.launch {
    try {
        sdk.auth.email.sendOTP("[email protected]")
        // Show OTP input UI
    } catch (e: Exception) {
        println("Failed to send OTP: ${e.message}")
    }
}

verifyOTP

Verify an email OTP code and authenticate the user.
suspend fun verifyOTP(token: String)

Parameters

  • token (String) - OTP code entered by user

Example

viewModelScope.launch {
    try {
        sdk.auth.email.verifyOTP("123456")
        // User is now authenticated
    } catch (e: Exception) {
        println("Invalid OTP: ${e.message}")
    }
}

resendOTP

Resend the email OTP.
suspend fun resendOTP()

Example

viewModelScope.launch {
    try {
        sdk.auth.email.resendOTP()
    } catch (e: Exception) {
        println("Failed to resend OTP: ${e.message}")
    }
}

sdk.auth.sms

sendOTP

Send a one-time password to a user’s phone number via SMS.
suspend fun sendOTP(phoneData: PhoneData)

Parameters

  • phoneData (PhoneData) - Phone data containing dial code, ISO code, and phone number

Example

viewModelScope.launch {
    try {
        val phoneData = PhoneData(
            dialCode = "+1",
            iso2 = "US",
            phone = "5551234567"
        )
        sdk.auth.sms.sendOTP(phoneData)
        // Show OTP input UI
    } catch (e: Exception) {
        println("Failed to send SMS: ${e.message}")
    }
}

verifyOTP

Verify an SMS OTP code and authenticate the user.
suspend fun verifyOTP(token: String)

Parameters

  • token (String) - OTP code entered by user

Example

viewModelScope.launch {
    try {
        sdk.auth.sms.verifyOTP("123456")
        // User is now authenticated
    } catch (e: Exception) {
        println("Invalid OTP: ${e.message}")
    }
}

resendOTP

Resend the SMS OTP.
suspend fun resendOTP()

Example

viewModelScope.launch {
    try {
        sdk.auth.sms.resendOTP()
    } catch (e: Exception) {
        println("Failed to resend SMS: ${e.message}")
    }
}

sdk.auth.social

connect

Authenticate with a social provider (Google, Apple, Farcaster).
suspend fun connect(provider: SocialAuthModule.SocialProvider)

Parameters

  • provider (SocialAuthModule.SocialProvider) - The social provider:
    • SocialAuthModule.SocialProvider.GOOGLE
    • SocialAuthModule.SocialProvider.APPLE
    • SocialAuthModule.SocialProvider.FARCASTER

Examples

viewModelScope.launch {
    try {
        // Google
        sdk.auth.social.connect(SocialAuthModule.SocialProvider.GOOGLE)
        // Apple
        sdk.auth.social.connect(SocialAuthModule.SocialProvider.APPLE)
        // Farcaster
        sdk.auth.social.connect(SocialAuthModule.SocialProvider.FARCASTER)
    } catch (e: Exception) {
        println("Sign-in failed: ${e.message}")
    }
}

sdk.auth.passkey

signIn

Authenticate with a passkey using the device’s biometric authentication.
suspend fun signIn()

Example

viewModelScope.launch {
    try {
        sdk.auth.passkey.signIn()
        // User is authenticated
    } catch (e: Exception) {
        println("Passkey sign-in failed: ${e.message}")
    }
}

sdk.auth.externalAuth

signInWithExternalJwt

Sign in using an external JWT token.
suspend fun signInWithExternalJwt(params: SignInWithExternalJwtParams)

Parameters

  • params (SignInWithExternalJwtParams) - Parameters containing the JWT token

Example

viewModelScope.launch {
    try {
        sdk.auth.externalAuth.signInWithExternalJwt(
            SignInWithExternalJwtParams(jwt = "your-jwt-token")
        )
    } catch (e: Exception) {
        println("JWT sign-in failed: ${e.message}")
    }
}

Authentication State

authenticatedUser

Get the current authenticated user (synchronous).
val user: UserProfile? = sdk.auth.authenticatedUser

Example

val user = sdk.auth.authenticatedUser
if (user != null) {
    println("User: ${user.email}")
}

authenticatedUserChanges

Observe authentication state changes (reactive flow).
val authenticatedUserChanges: StateFlow<UserProfile?>

Example

viewModelScope.launch {
    sdk.auth.authenticatedUserChanges.collect { user ->
        // Handle user state change
        isAuthenticated.value = user != null
    }
}

token

Get the current authentication token (synchronous).
val token: String? = sdk.auth.token

Example

val token = sdk.auth.token
if (token != null) {
    println("Token: ${token.take(20)}...")
}

tokenChanges

Observe authentication token changes (reactive flow).
val tokenChanges: StateFlow<String?>

Example

viewModelScope.launch {
    sdk.auth.tokenChanges.collect { token ->
        if (!token.isNullOrEmpty()) {
            // Token received, navigate to home
        }
    }
}

Logout

logout

Log out the current user.
suspend fun logout()

Example

viewModelScope.launch {
    try {
        sdk.auth.logout()
    } catch (e: Exception) {
        println("Logout failed: ${e.message}")
    }
}