如何在 Flutter web 中启用 Firebase 电话验证?我试过很多方法,但似乎不起作用,需要向用户发送短信代码

问题描述

我想通过使用firebase发送OTP来实现电话验证,怎么做? .我已尝试在 github 中关注此线程,但没有用,它没有帮助,signInwithphoneNumber 仅登录用户而不通过发送 SMS OTP 代码来验证用户,如何解决此问题?

Github 线程链接https://github.com/flutter/flutter/issues/46021

当我执行时抛出以下错误

Error: UnimplementedError: verifyPhoneNumber() is not supported on the web. Please use 
`signInWithPhoneNumber` instead.

有人可以帮我吗!!!

解决方法

你必须使用

FirebaseAuth auth = FirebaseAuth.instance;

// Wait for the user to complete the reCAPTCHA & for an SMS code to be sent.
ConfirmationResult confirmationResult = await auth.signInWithPhoneNumber('+44 7123 123 456');

然后这个来验证

UserCredential userCredential = await confirmationResult.confirm('123456');

您也可以根据自己的使用情况添加RecaptchaVerifier

ConfirmationResult confirmationResult = await auth.signInWithPhoneNumber('+44 7123 123 456',RecaptchaVerifier(
  container: 'recaptcha',size: RecaptchaVerifierSize.compact,theme: RecaptchaVerifierTheme.dark,));

你也可以编辑 reCaptcha

RecaptchaVerifier(
  onSuccess: () => print('reCAPTCHA Completed!'),onError: (FirebaseAuthException error) => print(error),onExpired: () => print('reCAPTCHA Expired!'),);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...