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 keyemail: 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
Session Management: Sessions are automatically managed by the SDK after creation.
Session Data: Contains user ID, company IDs, access token, and other metadata.
Email or Phone: At least one contact method (email or phone) is required.
SDK Sessions: SDK sessions use API keys for authentication.
Best Practices
Secure Storage: Store session tokens securely (encrypted shared preferences)
Error Handling: Always handle authentication errors appropriately
Session Validation: Check session validity before making API calls
Logout: Always call logout when user signs out
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