auth

This module provides authentication and session management functionality for the Smart1 SDK.

Overview

The auth module allows you to:

  • Create SDK sessions with API keys

  • Logout and finish sessions

Main Components

CreateSdkSession

Creates a new SDK session using an API key.

Parameters:

  • sdkApiKey: String - SDK API key

  • email: String? - User email (optional)

  • phoneNumber: String? - User phone number (optional)

Returns: ResultS1SDK<SessionData, ErrorS1SDK>

LogoutAndFinishSession

Logs out the user and finishes the current session.

Returns: ResultS1SDK<Boolean, ErrorS1SDK>

Usage Examples

Create SDK Session

import com.servinformacion.smart1sdk.android.auth.CreateSdkSession

suspend fun createSdkSession(apiKey: String, email: String) {
val createSdkSession = CreateSdkSession()

val result = createSdkSession(
sdkApiKey = apiKey,
email = email
)

when (result) {
is ResultS1SDK.Success -> {
val sessionData = result.data
println("SDK session created")
println("User ID: ${sessionData.userId}")
println("Companies: ${sessionData.companyIds}")
}
is ResultS1SDK.Error -> {
println("Failed to create SDK session")
}
}
}

Logout

import com.servinformacion.smart1sdk.android.auth.LogoutAndFinishSession

suspend fun logout() {
val logoutAndFinishSession = LogoutAndFinishSession()

val result = logoutAndFinishSession()

when (result) {
is ResultS1SDK.Success -> {
println("Logout successful")
// Navigate to login screen
}
is ResultS1SDK.Error -> {
println("Logout failed")
}
}
}

Important Notes

  1. Session Management: Sessions are automatically managed by the SDK after creation.

  2. Session Data: Contains user ID, company IDs, access token, and other metadata.

  3. Email or Phone: At least one contact method (email or phone) is required.

  4. SDK Sessions: SDK sessions use API keys for authentication.

Best Practices

  1. Secure Storage: Store session tokens securely (encrypted shared preferences)

  2. Error Handling: Always handle authentication errors appropriately

  3. Session Validation: Check session validity before making API calls

  4. Logout: Always call logout when user signs out

  5. API Key Security: Keep SDK API keys secure and never expose them in client code

Use Cases

  • SDK Integration: Create sessions for SDK-based applications

  • Session Management: Handle user sessions throughout app lifecycle

  • Logout: Properly terminate user sessions

Packages