Home > Software design >  Flutter Firebase Authentication requires 2 clicks for sign in
Flutter Firebase Authentication requires 2 clicks for sign in

Time:12-26

I just connected my app with firebase authentication but when i'm trying to click login button : it says

W/System  ( 6835): Ignoring header X-Firebase-Locale because its value was null.

And here is my code about firebase authentication : `

void signIn() async{
    final User? user = (await auth.signInWithEmailAndPassword(email: mailController.text, password: passController.text)).user;
    final uid = user!.uid;

    if(uid != null){
      if(this.mounted){
      setState((){
        success = 2;
        userMail = user.email!;
        userName = userMail;
        userName = userMail.replaceFirst(userName[0],"");
        userName = userName.substring(0,userName.indexOf("@"));
        userName = userName.replaceFirst(userName[0],userName[0].toUpperCase());
      });
    }}
    else{
      setState((){
        success = 3;
      });
    }
  }

`

if(success == 2){
                              if(userMail.startsWith("1")){
                                Navigator.pushReplacement(context,MaterialPageRoute(builder:(context) => OgrenciPage(mail:userName)));
                              }

``

I've tried to creating sha-1 key, closing bluetooth connection but it never works.

CodePudding user response:

I also face this problem earlier then solve this by making the function Future asyn{} and by using try catch block.

In my case i created the login class model where I perform all All login/signup functionalities

Here is the example code where you can see how to manage this:

class Login {
  FirebaseAuth firebaseAuth = FirebaseAuth.instance;


  Future<void> signInUser(
      String email, String password, BuildContext context) async {
    try {
      await firebaseAuth.signInWithEmailAndPassword(
          email: email, password: password);
    } on FirebaseAuthException catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text(
            e.toString(),
          ),
          backgroundColor: Colors.redAccent,
          duration: const Duration(seconds: 2),
        ),
      );
    } catch (error) {
      rethrow;
    }
  }
}
  • Related