Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用户在codeSent结束前登录(使用Firebase和Flatter进行电话身份验证)_Firebase_Flutter_Firebase Authentication - Fatal编程技术网

用户在codeSent结束前登录(使用Firebase和Flatter进行电话身份验证)

用户在codeSent结束前登录(使用Firebase和Flatter进行电话身份验证),firebase,flutter,firebase-authentication,Firebase,Flutter,Firebase Authentication,在我的颤振应用程序中,我编写了以下代码: Future<void> signInWithPhone({ @required String phoneNumber, }) async { Future<void> _verificationCompleted(PhoneAuthCredential credential) async { /// TODO: Remove this print() statement print('

在我的颤振应用程序中,我编写了以下代码:

Future<void> signInWithPhone({
    @required String phoneNumber,
  }) async {
    Future<void> _verificationCompleted(PhoneAuthCredential credential) async {
      /// TODO: Remove this print() statement
      print('ℹ verificationCompleted() started.');

      await _auth.signInWithCredential(credential);

      /// TODO: Remove this print() statement
      print('ℹ verificationCompleted() ended.');
    }

    Future<void> _verificationFailed(FirebaseAuthException exception) async {
      /// TODO: Remove this print() statement
      print('ℹ verificationFailed() started.');

      if (exception.code == 'invalid-phone-number') {
        print('The provided phone number is not valid.');
      }

      /// TODO: Remove this print() statement
      print('ℹ verificationFailed() ended.');
    }

    Future<void> _codeSent(String verificationId, int resendToken) async {
      /// TODO: Remove this print() statement
      print('ℹ codeSent() started.');

      /// TODO: Remove this print() statement
      print('ℹ User id: ${_auth.currentUser?.uid}');
      print('ℹ User phone number: ${_auth.currentUser?.phoneNumber}');

      /// TODO: Remove this print() statement
      print('ℹ smsCode() started.');

      String smsCode = await Future<String>.delayed(
        Duration(seconds: 3),
        () async => '123456',
      );

      /// TODO: Remove this print() statement
      print('ℹ smsCode() ended.');

      /// Create a PhoneAuthCredential with the code
      PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(
        verificationId: verificationId,
        smsCode: smsCode,
      );

      /// Sign the user in (or link) with the credential
      await _auth.signInWithCredential(phoneAuthCredential);

      /// TODO: Remove this print() statement
      print('ℹ codeSent() ended.');
    }

    Future<void> _codeAutoRetrievalTimeout(String verificationId) async {
      /// TODO: Remove this print() statement
      print('ℹ codeAutoRetrievalTimeout() started.');

      /// TODO: Remove this print() statement
      print('ℹ codeAutoRetrievalTimeout() ended.');
    }

    _auth.verifyPhoneNumber(
      phoneNumber: phoneNumber,
      verificationCompleted: _verificationCompleted,
      verificationFailed: _verificationFailed,
      codeSent: _codeSent,
      codeAutoRetrievalTimeout: _codeAutoRetrievalTimeout,
    );
  }
因此,用户是在
codeSent()
函数结束之前登录的

❔ 如何确定用户输入的代码是否正确?我如何知道用户是否输入了他真正拥有的电话号码

多谢各位

I/flutter (13129): ℹ codeSent() started.
I/flutter (13129): ℹ User id: <HERE IT’S SHOWN THE USER ID>
I/flutter (13129): ℹ User phone number: <PHONE NUMBER HERE>
I/flutter (13129): ℹ smsCode() started.
I/flutter (13129): ℹ smsCode() ended.
I/BiChannelGoogleApi(13129): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal. [...]
D/FirebaseAuth(13129): Notifying id token listeners about user ( <ID TOKEN HERE> ).
I/flutter (13129): ℹ codeSent() ended.
I/flutter (13129): ℹ codeAutoRetrievalTimeout() started.
I/flutter (13129): ℹ codeAutoRetrievalTimeout() ended.