Возможно ли использовать этот API с аутентификацией телефона firebase? - PullRequest
0 голосов
/ 15 февраля 2020

Возможно ли реализовать автоматическое c заполнение кода подтверждения SMS с помощью Firebase? Я работаю над приложением Flutter. использовал этот плагин firebase_auth .

Возможно ли использовать этот API. https://developers.google.com/identity/sms-retriever/overview

Возможно ли использовать этот сторонний плагин? плагин автоматического заполнения флаттера

этот метод автоматически проверяет код. тот же телефон, тот же номер

 void _verifyPhoneNumber() async {

    final PhoneVerificationCompleted verificationCompleted =
        (AuthCredential phoneAuthCredential) {

        _auth.signInWithCredential(phoneAuthCredential).then((v) async {
          customFlushBar(
              context, 'This device and phone number is already authenticated.',3);
          if (v.user != null) {
              //add user to firestore
                  Navigator.of(context).pushNamedAndRemoveUntil(
                      '/homePage', (Route<dynamic> route) => false);
          } else {
            customFlushBar(context, 'Server Error !',3);
          }
        }).catchError((error)=>{
          customFlushBar(context,
              'Somthing Happening, Please try again! It might be a server error or maybe no internet connection access',7)});
    };

    final PhoneVerificationFailed verificationFailed =
        (AuthException authException) {
      customFlushBar(context,
          'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}',7);
    };

    final PhoneCodeSent codeSent =
        (String verificationId, [int forceResendingToken]) async {
      customFlushBar(
          context, 'Please check your phone for the verification code.',5);
      setState(() {
        this._verificationId = verificationId;
         this.status = AuthStatus.SMS_AUTH;
      });
    };

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

    await _auth.verifyPhoneNumber(
        phoneNumber: selectionCountryCode + phoneNumberController.text,
        timeout: const Duration(seconds: 30),
        verificationCompleted: verificationCompleted,
        verificationFailed: verificationFailed,
        codeSent: codeSent,
        codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
  }

если пользователь использовал другой номер телефона, то получил смс сообщение

void _signInWithPhoneNumber() async {
      final AuthCredential credential = PhoneAuthProvider.getCredential(
        verificationId: _verificationId,
        smsCode: smsController.text,
      );

      final FirebaseUser user =
          (await _auth.signInWithCredential(credential)).user;

      if (user != null) {
        //add to user firestore and Navigate to the home page
         Navigator.of(context).pushNamedAndRemoveUntil(
                    '/homePage', (Route<dynamic> route) => false);
      } else {
        customFlushBar(context, 'Sign in failed',5);
      }
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...