1

我想通过使用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.

有人可以帮帮我吗!!!

4

1 回答 1

2

你必须使用

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!'),
);
于 2021-06-23T07:20:50.297 回答