【问题标题】:flutter phone auth doens't work in my boss phone颤振电话身份验证在我的老板电话中不起作用
【发布时间】:2021-02-27 10:13:12
【问题描述】:

你好

我正在尝试使用颤振进行手机身份验证 我设法实现但在我的老板手机(android)中不起作用 在我的手机中它可以工作。 这就是为什么我快疯了

我想用有线调试模式连接老板电话 但我的老板拒绝了。 ????????????

这是我的代码

Future createUserWithPhone({String phoneNumber, BuildContext context}) async {
    String phoneNumberWith82 = '+82 $phoneNumber';

    await fAuth.verifyPhoneNumber(
        phoneNumber: phoneNumberWith82,
        timeout: Duration(seconds: 60),
        verificationCompleted: (AuthCredential authCredential) async {
          print('here verificationcompleted');
✅ not a big deal, verificationCompleted doesn't work don't know why
          await fAuth
              .signInWithCredential(authCredential)
              .then((AuthResult result) {
            Fluttertoast.showToast(
              msg: "success",
              backgroundColor: Colors.black26,
              textColor: Colors.white,
            );
          }).catchError((e) {
            print('Error Occurs ⭐3');
            return "error";
          });
        },
        verificationFailed: (AuthException exception) {
          Fluttertoast.showToast(
              msg: 'too many request',
              toastLength: Toast.LENGTH_LONG,
              gravity: ToastGravity.BOTTOM,
              timeInSecForIosWeb: 1,
              backgroundColor: Colors.red,
              textColor: Colors.white,
              fontSize: 16.0);
          return "error";
        },
        codeSent: (String verificationId, [int forceResendingToken]) async {
          final _codeController = TextEditingController();
          await showDialog(
            context: context,
            barrierDismissible: false,
            builder: (context) => AlertDialog(
              title: Text("write auth 6digit"),
              content: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  TextField(
                    controller: _codeController,
                    keyboardType: TextInputType.number,
                  ),
                ],
              ),
              actions: <Widget>[
                FlatButton(
                  child: Text("verify"),
                  textColor: Constants.kPrimaryOrange,
                  // color: Constants.kPrimaryOrange,
                  onPressed: () async {

                    var _credential = PhoneAuthProvider.getCredential(
                        verificationId: verificationId,
                        smsCode: _codeController.text.trim());

✅ Error Occurs HERE ✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅
                    await fAuth
                        .signInWithCredential(_credential)
                        .then((AuthResult result) async {
                     
                      var snapshot = await Firestore.instance
                          .collection('users')
                          .where('pid', isEqualTo: result.user.phoneNumber)
                          .getDocuments();

                      /// id doesn't exist.
                      if (snapshot.documents.length == 0) {
                        
                        await Firestore.instance
                            .collection('users')
                            .document(result.user.uid)
                            .setData({
                          'uid': result.user.uid,
                          'pid': result.user.phoneNumber,
                          'name': randomName,
                          'createdAt': DateTime.now(),
                          'storeName': '',                         
                        });
                        Fluttertoast.showToast(
                          msg: "33",
                          backgroundColor: Colors.black26,
                          textColor: Colors.white,
                        );
                        
                      } else {
                        Fluttertoast.showToast(
                          msg: " id exists",
                          backgroundColor: Colors.black26,
                          textColor: Colors.white,
                        );
                      
                      }
                      setUser(result.user);
                      
                      Navigator.pushNamedAndRemoveUntil(
                          context, SplashScreen.id, (route) => false,
                          arguments: result.user);
              
✅ catch               }).catchError((e) {
                      Fluttertoast.showToast(                         
                          msg: e.toString(),
                          toastLength: Toast.LENGTH_LONG,
                          gravity: ToastGravity.BOTTOM,
                          timeInSecForIosWeb: 1,
                          backgroundColor: Colors.red,
                          textColor: Colors.white,
                          fontSize: 16.0);
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) =>
                                ErrorReading(errorMsg: e.toString())),
                      );
                      // Navigator.pop(context);

                      return "error";
                    });
                  },
                ),
                FlatButton(
                  child: Text("close"),
                  textColor: Constants.kPrimaryOrange,
                  // color: Constants.kPrimaryOrange,
                  onPressed: () {
                    print('Error Occurs ⭐');
                    Navigator.pop(context);
                  },
                )
              ],
            ),
          );
        },
        codeAutoRetrievalTimeout: (String verificationId) {
          verificationId = verificationId;
        });

我不知道这个问题的原因,所以我无法解决它。 我曾经举杯寻找错误点。 然后我找到了✅看看这个表情符号

有人吗?

  firebase_auth: ^0.16.1
  firebase_core: ^0.4.0
  cloud_firestore: ^0.13.0
  firebase_storage: ^3.1.6 

我用核心 ^5 尝试了 firebase_auth ^18,但有很多地方可以更改最近的代码,所以我试图弄清楚这些版本

【问题讨论】:

  • 您是否在“项目概览 > 项目设置 > 您的应用 > 您的 Android 应用 > SHA 证书指纹”中添加了 Android Studio 的 SHA-1 指纹?我知道 Firebase 电话验证需要您应用的 SHA-1 指纹才能正常工作(在调试和发布中)。
  • 此外,您需要在 GCP 中激活 Device Check API。你试过吗?看看这些steps
  • 感谢您的回复,#Martin:是的,我做到了???? #Ayush Surana : 我没有激活设备检查 API,所以我激活并等待我的老板

标签: firebase flutter firebase-authentication


【解决方案1】:

按照提到的步骤here

您需要添加 SHA-1 指纹并启用设备检查 API 以在 Android 中进行电话验证。

如果您需要电话验证的代码示例才能工作 firebase_auth ^18 与核心 ^5,请告诉我将编辑此答案。

【讨论】:

  • 我激活了设备检查 API,现在我可以在激活前收到错误消息,我什至无法收到错误消息。好的好的它是过期的错误。这是新阶段,(我可以搜索关于 firebaseauth ^18with core ^5)=(我不想打扰你)谢谢 ?
猜你喜欢
  • 1970-01-01
  • 2021-03-22
  • 2020-06-06
  • 2021-06-12
  • 1970-01-01
  • 2020-03-26
  • 2020-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多