Search code examples
firebase-authenticationflutter-web

Get FirebaseAuthPlatform for Flutter web RecaptchaVerifier


SITUATION: I'm in the process of implementing Firebase phone sign-in on flutter web. In doing so, I want to customize the reCAPTCHA that is called by the signInWithPhoneNumber function as outlined in the Firebase documentation.

final ConfirmationResult confirmationResult = await auth.signInWithPhoneNumber(
  phoneNumber, verifier_should_go_here
);

COMPLICATION: I am trying to implement the RecaptchaVerifier, but it has a required parameter called FirebaseAuthPlatform, and I can't figure out how to generate this parameter for my app.

QUESTION: How can I create a RecaptchaVerifier to pass to the signInWithPhoneNumber function on flutter web?


Solution

  • 3 easy steps:

    • You add the firebase_auth_platform_interface dependency to your pubspec.yaml file with flutter pub add firebase_auth_platform_interface
    • You import the package like this: import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart' show FirebaseAuthPlatform;
    • Inside the constructor for RecaptchaVerifier, you use FirebaseAuthPlatform.instance