setupNativeAuthHandler method

void setupNativeAuthHandler(
  1. InAppWebViewController controller
)

Sets up the nativeauth JavaScript handler used by WebView social buttons.

The WebView should call: window.flutter_inappwebview.callHandler('nativeauth', 'google') (or 'apple'). This will start Amplify Hosted UI and return the resulting Cognito localStorage-style key/value map back to JavaScript.

If saveNativeAuthTokens is provided, it is invoked after sign-in to allow the caller (page) to persist tokens in its preferred format.

Implementation

void setupNativeAuthHandler(InAppWebViewController controller) {
  controller.addJavaScriptHandler(
    handlerName: 'nativeauth',
    callback: (args) async {
      final providerArg = args.isNotEmpty ? args[0] : null;
      final provider =
          providerArg is String ? providerArg.trim().toLowerCase() : '';
      _log('RemitWebview: nativeauth called with provider: $provider');

      final result = await AuthService().signInWithNativeAuth(provider);

      // Return the result back to the WebView JS caller.
      return result;
    },
  );
}