Authentication state
In Flutter, you access auth state via theTurnkeyProvider (a ChangeNotifier). The presence of a session indicates the user is authenticated.
lib/widgets/auth_status.dart
onSessionSelected callback in TurnkeyConfig to handle post-authentication logic, such as redirecting.
snippet
Listening to provider updates
TurnkeyProvider is a ChangeNotifier, so you can attach listeners to respond to internal state changes (e.g., when wallets/users are fetched). This pattern is useful when you want to mirror provider data into local widget state.
Below is an example (adapted from the demo app) that keeps a local selectedWallet/selectedAccount in sync with the provider:
lib/screens/dashboard.dart
Tips
- Use
addListener/removeListenerfor one-off reactions to state changes.- Use
Consumer,Selector, orcontext.selectwhen you want automatic rebuilds based on specific slices of provider state.- Avoid calling
setStateinside your listener after the widget is disposed — always guard withif (!mounted) return;orif (!context.mounted) return;.