Autenticacao via OTP

Home   »   Autenticacao via OTP

 Future signUpWithOTP() async {
    try {
      setState(() {
        _isProcessing = true;
      });
      var phoneNumber = "+55 ${_phoneOTPController.text.trim()}";
      var verifyPhoneNumber = firebaseAuth.verifyPhoneNumber(
        phoneNumber: phoneNumber,
        verificationCompleted: (phoneAuthCredential) async {
          final _signInWithCredential = await firebaseAuth.signInWithCredential(phoneAuthCredential);
          if (_signInWithCredential != null) {
            DebugPrint.print("Usuário: ${_signInWithCredential.toString()} registrado");
          }
        },
        verificationFailed: (FirebaseAuthException error) {
          DebugPrint.error("Erro ao enviar o código: $error");
          setState(() {
            _isProcessing = false;
          });
        },
        codeSent: (verificationId, [forceResendingToken]) {
          DebugPrint.print("Código: $verificationId");
          setState(() {
            _isProcessing = false;
          });
        },
        codeAutoRetrievalTimeout: (String verificationId) {
          DebugPrint.print("Código: $verificationId");
          setState(() {
            _isProcessing = false;
          });
        },
        timeout: Duration(seconds: 60),
      );
      await verifyPhoneNumber;
    } catch (e) {
      DebugPrint.error("DebugError: Erro $e ao executar o signUpWithOTP do _SignupPageState");
    } finally {
      setState(() {
        _isProcessing = false;
      });
    }
  }

Leave a Reply

Your email address will not be published.