Skip to main content
Manage authentication state and wallet updates with Kotlin Flow.

State Flows

The SDK provides flows that emit updates:
  • authenticatedUserChanges - User login/logout
  • tokenChanges - Auth token updates
  • userWalletsChanges - Wallet changes
  • isAuthenticatedFlow - Auth status
Your UI updates automatically when you collect these flows.

Implementation Patterns

1. Basic Session Management

Start with a simple session management setup using a ViewModel:

2. Using Session Manager in Jetpack Compose

3. Complete Session Manager

For production apps, implement a comprehensive session manager:

4. Home Screen with Session Management

5. Navigation Based on Auth State

Handle navigation when authentication state changes:

Best Practices

1. Always Collect on Main Dispatcher

When updating UI state from flows, make sure to use the main dispatcher:

2. Initialization Order

Always initialize the SDK at app launch:

3. Check Initial State

Always check the current state before setting up listeners:

4. Handle Wallet Creation Loading State

Wallets are created asynchronously after authentication:

Troubleshooting

Common Issues

State not updating
  • Ensure you’re using viewModelScope.launch for coroutine collection
  • Verify flows are collected in the correct scope
  • Check that your ViewModel is using StateFlow and collectAsState() properly
Navigation not working after login
  • Make sure you’re subscribed to authenticatedUserChanges before the user authenticates
  • Check that your navigation logic handles the case where user is already authenticated
Wallets not appearing
  • Wallets are created asynchronously after authentication
  • Collect from userWalletsChanges to receive updates
  • Check that embedded wallets are enabled in your Dynamic dashboard
  • Ensure proper Flow collection with collectAsState() in Compose

Debug Session State

Add logging to understand state changes:

What’s Next

Now that you have session management set up, you can:
  1. Authentication Guide - Implement user authentication flows
  2. Wallet Operations - Work with wallet balances and signing
  3. EVM Operations - Perform EVM transactions
  4. Solana Operations - Send Solana transactions
Last modified on February 3, 2026