Last updated

Flutter advanced setup

In this guide, you'll find an overview and best practices for enabling advanced features and using built in functions for biometric authentication (passkeys) and step-up.

Custom loader iOS

To customize the loader for iOS when using Embedded mode, you can set up a custom loader by modifying your AppDelegate.swift file. The custom loader will be displayed during authentication processes.

First, ensure that Embedded mode is enabled in your configuration.

 <plist version="1.0">
<dict>
	<key>embeddedMode</key>
	<true/>
	...
</dict>
</plist>

Here's how to implement a custom loader:

import SwiftUI
import FronteggSwift

@main
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
         ...
        // Setup Loader for Frontegg Embedded Loading
        // Can be any view
        DefaultLoader.customLoaderView = AnyView(Text("Loading..."))
        
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    ...
}

Custom loader Android

To customize the loader for Android when using Embedded Activity mode, you can set up a custom loader by modifying your MainActivity.kt file. The custom loader will be displayed during authentication processes.

First, ensure that Embedded Activity mode is enabled in your configuration.

Here's how to implement a custom loader:


import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
import android.widget.ProgressBar
import com.frontegg.android.ui.DefaultLoader
import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    // Setup Loader for Frontegg Embedded Activity Loading
    DefaultLoader.setLoaderProvider {
      // Can be any view
      val progressBar = ProgressBar(it)
      val colorStateList = ColorStateList.valueOf(Color.GREEN)
      progressBar.indeterminateTintList = colorStateList

      progressBar
    }
  }
}

Step-up authentication

Step-up authentication allows you to temporarily elevate a user's authentication level to perform sensitive actions. This is useful for operations like updating credentials, accessing confidential data, or performing secure transactions.

maxAge (optional): How long the elevated session is considered valid, in seconds.

completion: A closure called after authentication finishes. If step-up fails, it receives an error.

stepUp -

Starts the step-up authentication flow. This will usually trigger a stronger authentication method ( e.g. biometric, MFA, etc).

await stepUp(maxAge: Duration(minutes: 5));

isSteppedUp -

This method checks if the user has recently completed a step-up authentication and whether it is still valid.


final isElevated = await isSteppedUp(maxAge: Duration(minutes: 5));
if (isElevated) {
    // Proceed with sensitive action
} else {
    // Prompt user to step up
}

Example:


Future<void> performSensitiveAction() async {
    final steppedUp = await isSteppedUp(maxAge: Duration(minutes: 5));
      
    if (!steppedUp) {
        await stepUp(maxAge: Duration(minutes: 5));
    }
      
    // Continue with the sensitive action
}

Frontegg Flutter API Reference

Properties

PropertyDescription
currentStateGets the current state of the Frontegg instance. Returns a FronteggState which includes information such as authentication status, loading status, and user details.
stateChangedA stream that emits changes to the FronteggState. Provides real-time updates on the state of authentication, user details, and loading statuses.

Methods

Authentication methods
MethodParametersDescription
loginloginHint (optional): StringInitiates the authentication process. loginHint pre-fills the login field in the Frontegg Login Box.
loginWithPasskeysNoneAuthenticates the user using passkeys.
registerPasskeysNoneRegisters passkeys for the user.
logoutNoneLogs out the user and clears user-related data.
refreshTokenNoneRefreshes the authentication token if needed. Returns true if successful.
Social & direct login methods
MethodParametersDescription
directLogin- url (required): String
- ephemeralSession: bool = true
- additionalQueryParams: Map<String, String>?
Initiates a direct login using a provided URL.
socialLogin- provider (required): FronteggSocialProvider
- ephemeralSession: bool = true
- additionalQueryParams: Map<String, String>?
Initiates a social login using the specified provider (e.g., Google, Facebook).
customSocialLogin- id (required): String
- ephemeralSession: bool = true
- additionalQueryParams: Map<String, String>?
Initiates a custom social login using a unique identifier.
Account (tenant) management
MethodParametersDescription
switchTenanttenantId (required): StringSwitches the user's active tenant. IDs available from User.tenants.tenantId.
Authorization & security
MethodParametersDescription
requestAuthorize- refreshToken (required): String
- deviceTokenCookie: String?
Initiates authorization request. Returns FronteggUser if successful, null if fails.
isSteppedUpmaxAge: Duration?Checks if user has completed step-up authentication.
stepUpmaxAge: Duration?Initiates the step-up authentication process.
Utility methods
MethodParametersDescription
disposeNoneCancels the subscription to the state stream. Call when object is no longer needed.
getConstantsNoneFetches the Frontegg constants containing configuration values. Returns FronteggConstants.
Error handling

All methods can throw a FronteggException for platform-specific errors. The error handling system automatically converts platform exceptions to FronteggException instances.

Common error scenarios:
  • Authentication failures
  • Network connectivity issues
  • Invalid parameters
  • Platform-specific errors