Skip to main content
Turnkey’s Flutter SDK makes authentication simple. You can call specific login and signup functions (email/SMS OTP, passkeys, or social logins) to build your own UI and auth flow.

Authentication state

To check if a user is authenticated, you can use the authState variable from the TurnkeyProvider. authState can be one of the following:
  • AuthState.authenticated: The user has a stored session.
  • AuthState.unauthenticated: The user does not have a stored session.
  • AuthState.loading: The provider is initializing. Turnkey is checking for any existing stored sessions or restoring state. UI should show a splash or progress indicator.
You can consume authState in any widget using a Consumer<TurnkeyProvider>:
lib/widgets/auth_status.dart
You can also set up an 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 user/wallets are fetched or when authState changes). 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/removeListener for one-off reactions to state changes.
  • Use Consumer, Selector, or context.select when you want automatic rebuilds based on specific slices of provider state.
  • Avoid calling setState inside your listener after the widget is disposed — always guard with if (!mounted) return; or if (!context.mounted) return;.

Customize sub-organization creation

Need to configure default user names, passkey names, wallet creations or anything sub-org related? You can learn more about customizing the sub-orgs you create in the Sub-Organization Customization. Follow the guides below to learn how to set up email and SMS authentication, passkey authentication, and social logins in your Flutter app.

Email & SMS

Learn how to set up email and SMS authentication in your Flutter app.

Passkey Authentication

Learn how to set up passkey authentication in your Flutter app.

Social Logins

Discover how to add social logins (Google, Apple, X, Discord) and handle wallet creation and account derivation.