【问题标题】:Flutter Firebase authentication only work when you give test phone numberFlutter Firebase 身份验证仅在您提供测试电话号码时才有效
【发布时间】:2020-03-11 12:48:42
【问题描述】:

我的代码可以正常工作,但它仅验证 Firebase 身份验证中给出的测试电话号码。

当我尝试使用其他号码时,会直接转到 PhoneVerificationFailed(),这是我从此方法获得的异常消息:-

错误信息

电话号码验证失败。代码:firebaseAuth。消息:此应用无权使用 Firebase 身份验证。请确认在 Firebase 控制台中配置了正确的包名称和 SHA-1。 [应用验证失败]

请看一下,分享你的想法,可能是我犯了一些错误。


  // Example code of how to verify phone number
  void _verifyPhoneNumber() async {
    setState(() {
      _message = '';
    });
    final PhoneVerificationCompleted verificationCompleted =
        (AuthCredential phoneAuthCredential) {
      _auth.signInWithCredential(phoneAuthCredential);
      setState(() {
        _message = 'Received phone auth credential: $phoneAuthCredential';
      });
    };

    final PhoneVerificationFailed verificationFailed =
        (AuthException authException) {
      setState(() {
        _message =
            'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}';
      });
    };

    final PhoneCodeSent codeSent =
        (String verificationId, [int forceResendingToken]) async {
      widget._scaffold.showSnackBar(const SnackBar(
        content: Text('Please check your phone for the verification code.'),
      ));
      _verificationId = verificationId;
    };

    final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
        (String verificationId) {
      _verificationId = verificationId;
    };

    await _auth.verifyPhoneNumber(
        phoneNumber: _phoneNumberController.text,
        timeout: const Duration(seconds: 5),
        verificationCompleted: verificationCompleted,
        verificationFailed: verificationFailed,
        codeSent: codeSent,
        codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
  }





  // Example code of how to sign in with phone.
  void _signInWithPhoneNumber() async {
    final AuthCredential credential = PhoneAuthProvider.getCredential(
      verificationId: _verificationId,
      smsCode: _smsController.text,
    );
    final FirebaseUser user =
        (await _auth.signInWithCredential(credential)).user;
    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);
    setState(() {
      if (user != null) {
        _message = 'Successfully signed in, uid: ' + user.uid;
      } else {
        _message = 'Sign in failed';
      }
    });
  }

如果你们需要完整代码,请评论它,然后我会分享完整代码

【问题讨论】:

    标签: firebase flutter firebase-authentication


    【解决方案1】:

    在 Firebase 端未完成 SHA-1 配置,一旦 SHA-1 配置完成,它将开始完美运行。

    查看此链接以配置 SHA-1

    https://stackoverflow.com/a/56091158/12072674

    【讨论】:

      猜你喜欢
      • 2021-06-11
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      • 2021-06-10
      • 2021-04-03
      • 2020-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多