Martin Reindl
Martin Reindl

Reputation: 1603

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?

Upvotes: 5

Views: 1896

Answers (2)

Шахзод
Шахзод

Reputation: 311

You have two ways:

  1. Use this import (it's included in "firebase_auth_web"):
import 'package:firebase_auth_web/firebase_auth_web.dart';

RecaptchaVerifier(
  auth: FirebaseAuthWeb.instance
)
  1. Use the package "firebase_auth_oauth_platform_interface"
import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart';

RecaptchaVerifier(
  auth: FirebaseAuthPlatform.instance
)

Upvotes: 3

Sebastien
Sebastien

Reputation: 4325

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

Upvotes: 8

Related Questions