> ## Documentation Index
> Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication Functions

## sdk.auth.email

### sendOTP

Send a one-time password to a user's email address.

```kotlin theme={"system"}
suspend fun sendOTP(email: String)
```

#### Parameters

* **email** (String) - User's email address

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        sdk.auth.email.sendOTP("user@example.com")
        // Show OTP input UI
    } catch (e: Exception) {
        println("Failed to send OTP: ${e.message}")
    }
}
```

### verifyOTP

Verify an email OTP code and authenticate the user.

```kotlin theme={"system"}
suspend fun verifyOTP(token: String)
```

#### Parameters

* **token** (String) - OTP code entered by user

#### Example

```kotlin theme={"system"}
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.

```kotlin theme={"system"}
suspend fun resendOTP()
```

#### Example

```kotlin theme={"system"}
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.

```kotlin theme={"system"}
suspend fun sendOTP(phoneData: PhoneData)
```

#### Parameters

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

#### Example

```kotlin theme={"system"}
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.

```kotlin theme={"system"}
suspend fun verifyOTP(token: String)
```

#### Parameters

* **token** (String) - OTP code entered by user

#### Example

```kotlin theme={"system"}
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.

```kotlin theme={"system"}
suspend fun resendOTP()
```

#### Example

```kotlin theme={"system"}
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).

```kotlin theme={"system"}
suspend fun connect(provider: SocialAuthModule.SocialProvider)
```

#### Parameters

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

#### Examples

```kotlin theme={"system"}
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.

```kotlin theme={"system"}
suspend fun signIn()
```

#### Example

```kotlin theme={"system"}
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.

```kotlin theme={"system"}
suspend fun signInWithExternalJwt(params: SignInWithExternalJwtParams)
```

#### Parameters

* **params** (SignInWithExternalJwtParams) - Parameters containing the JWT token

#### Example

```kotlin theme={"system"}
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).

```kotlin theme={"system"}
val user: UserProfile? = sdk.auth.authenticatedUser
```

#### Example

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

### authenticatedUserChanges

Observe authentication state changes (reactive flow).

```kotlin theme={"system"}
val authenticatedUserChanges: StateFlow<UserProfile?>
```

#### Example

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

### token

Get the current authentication token (synchronous).

```kotlin theme={"system"}
val token: String? = sdk.auth.token
```

#### Example

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

### tokenChanges

Observe authentication token changes (reactive flow).

```kotlin theme={"system"}
val tokenChanges: StateFlow<String?>
```

#### Example

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

## Logout

### logout

Log out the current user.

```kotlin theme={"system"}
suspend fun logout()
```

#### Example

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