Skip to main content

Use the API from Flutter

The thefaithapp_auth package signs a member in through TheFaithApp and gives your Flutter app an authenticated client for v1 API requests. Your app does not need to host a callback website.

Before you begin

You need:
  • a Flutter app targeting Android or iOS
  • its Android application ID or iOS bundle ID
  • a client API key from Settings > Developer Access
1

Add the package

Add the package to your pubspec.yaml:
Install it:
Stop and rebuild the app after adding the package so Flutter can register its platform code.
2

Register your Flutter app

In the TheFaithApp dashboard:
  1. Open Settings > Developer Access.
  2. Click Add Flutter app.
  3. Append .thefaithapp to your application ID.
  4. Add the app and copy your client API key.
For an application ID of com.example.app, enter:
The dashboard creates the callback expected by the package:
Use a lowercase reverse-domain application ID containing letters, numbers, and dots. Avoid underscores because they cannot be used in a callback URI scheme.
3

Check platform requirements

Android
  • Set minSdk to 24 or newer.
  • No manual callback activity is required.
iOS
  • Set the deployment target to iOS 13.0 or newer.
  • Enable Keychain Sharing for the Runner target in Xcode.
No callback URL type needs to be added manually when using the package’s default system authentication session.
4

Initialize the SDK

Provide the client key when creating TheFaithAppAuth:
Pass the value from your build environment instead of committing it to the repository:
5

Sign in a member

Open hosted sign-in from a button or another user action:
After the member finishes signing in, the package returns to the app and saves the session securely.
6

Call a v1 endpoint

Use the authorized client for protected API requests:
Use auth.apiUri('/v1/...') for other endpoints in the API Reference.

Restore the saved session

Check for a saved session when the app starts:
If currentSession() returns null, show the sign-in action again.

Sign out

Revoke the member session and remove its saved copy:
Release the SDK’s resources when the owning service or widget is disposed:

Handle SDK errors

Catch TheFaithAuthException to show an appropriate message:

Troubleshooting

Next steps

  • Browse the endpoint groups in the API Reference navigation.
  • Read Pagination and Errors before loading lists or adding retry behavior.
  • Use the public standalone sample as a compact reference implementation.