GithubHelp home page GithubHelp logo

Comments (5)

Tkko avatar Tkko commented on June 12, 2024

If you are using FIrebaseAuth you don't need to use smart_auth to get the SMS code. You just need to handle verificationCompleted.

    await FirebaseAuth.instance.verifyPhoneNumber(
      verificationCompleted: (PhoneAuthCredential credential) {
        pinController.setText(credential.smsCode);
      },
      verificationFailed: (FirebaseAuthException e) {},
      codeSent: (String verificationId, int? resendToken) {},
      codeAutoRetrievalTimeout: (String verificationId) {},
    );

from flutter_smart_auth.

sjdpk avatar sjdpk commented on June 12, 2024

I receive messages on my phone, but the auto-fill feature is not working. Here is my code for this issue. Even after receiving a message, the controller value remains empty. Do I need to update something in this code, or is there any configuration I have to adjust in the project?
Here is my sample code:

import 'dart:developer';

import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:pinput/pinput.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final scaffoldKey = GlobalKey();
  final TextEditingController controller = TextEditingController();

  sendOtp() async {
    FirebaseAuth auth = FirebaseAuth.instance;
    await auth.verifyPhoneNumber(
      phoneNumber: "+9779860718700",
      verificationCompleted: (PhoneAuthCredential credential) async {
        controller.setText(credential.smsCode ?? "");
      },
      verificationFailed: (FirebaseAuthException e) {
        log('The provided phone number is not valid.${e.code}');
      },
      codeSent: (String verificationId, int? resendToken) {},
      codeAutoRetrievalTimeout: (String verificationId) {},
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: scaffoldKey,
        appBar: AppBar(
          title: const Text('Plugin example app'),
          actions: [
            IconButton(
              onPressed: () async {
                controller.setText("123456");
              },
              icon: const Icon(Icons.home),
            ),
            IconButton(
              onPressed: () async {
                log("This is log ${controller.text}");
              },
              icon: const Icon(Icons.abc),
            ),
            IconButton(
              onPressed: () => sendOtp(),
              icon: const Icon(Icons.send),
            )
          ],
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(40.0),
            child: Pinput(
              length: 6,
              androidSmsAutofillMethod: AndroidSmsAutofillMethod.none,
              // androidSmsAutofillMethod: AndroidSmsAutofillMethod.smsUserConsentApi,
              controller: controller,
            ),
          ),
        ),
      ),
    );
  }
}

from flutter_smart_auth.

Tkko avatar Tkko commented on June 12, 2024

Is the verificationCompleted method called at all?

from flutter_smart_auth.

sjdpk avatar sjdpk commented on June 12, 2024

After invoking the function to send the OTP, the reCAPTCHA check occurs in Chrome. Upon successful verification, the page returns to the app. Subsequently, the SMS is received, but the 'verificationCompleted' method doesn't trigger. Is there an error in my code, or do I need to make any updates? Could you please review my code and correct it if necessary? Thank you.

from flutter_smart_auth.

Tkko avatar Tkko commented on June 12, 2024

The code looks good, but I don't understand why firebase_auth is redirecting you to the reCAPTCHA.

from flutter_smart_auth.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.