问题描述
我想通过使用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!'),);