8

I linked my app with firebase but when I try to signup with a new user in the app I am getting this error: Ignoring header X-Firebase-Locale because its value was null. that is the auth screen code:

class Authscreen extends StatefulWidget {
  @override
  Authscreenstate createState() => Authscreenstate();
}

final auth = FirebaseAuth.instance;

class Authscreenstate extends State<Authscreen> {
  void submitauthform(String email, String password, String username,
      bool islogin, BuildContext ctx) async {
    UserCredential authres;
    try {
      if (islogin == true) {
        authres = await auth.signInWithEmailAndPassword(
            email: email, password: password);
      } else {
        authres = await auth.createUserWithEmailAndPassword(
            email: email, password: password);
      }
    } on FirebaseAuthException catch (e) {
      String message = "error";
      if (e.code == 'weak-password') {
        message = 'The password provided is too weak.';
      } else if (e.code == 'email-already-in-use') {
        message = 'The account already exists for that email.';
      } else if (e.code == 'user-not-found') {
        message = 'No user found for this email.';
      } else if (e.code == 'wrong-password') {
        message = 'Wrong user privded for that user';
      }
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text(message),
          backgroundColor: Theme.of(ctx).errorColor,
        ),
      );
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Theme.of(context).accentColor,
      body: Authform(submitauthform),
    );
  }
}
george derderian
  • 173
  • 2
  • 11

3 Answers3

3

My Solution

For clarification, the code is a system warning, not an error hence should not affect the system's processes.

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

From the above code, you have limited the program to utilize only a few firebase authentication errors.

  try {
       ...
    } on FirebaseAuthException catch (e) {
      ...
      if (e.code == 'weak-password') {
        ...
      } else if (e.code == 'email-already-in-use') {
        ...
      } else if (e.code == 'user-not-found') {
        ...
      } else if (e.code == 'wrong-password') {
        ...
      }
      ...
    } catch (e) {
      print(e);
    }

That's good for user experience but what about other FirebaseAuthException? How will you know? (This is the problem one will face).

Hence, in order to get all the firebase exceptions and know what's happening use print(e.code) within the FirebaseAuthException catch.

Example:

  try {
       ...
    } on FirebaseAuthException catch (e) {
      ...
      if (e.code == 'weak-password') {
        ...
      } else if (e.code == 'email-already-in-use') {
        ...
      } else if (e.code == 'user-not-found') {
        ...
      } else if (e.code == 'wrong-password') {
        ...
      }
      ...
      print(e.code) //Add this line to see other firebase exceptions.
    } catch (e) {
      print(e);
    }

This should help you to know where you are stuck.

Any misconceptions about my code and bugs, don't hesitate to comment. I will reply as soon as possible.

4xMafole
  • 479
  • 1
  • 8
  • 20
  • Thanks for this. Turns out that after adding your print line I got "[firebase_auth/unknown] com.google.firebase.FirebaseException: An internal error has occurred. [ Cleartext HTTP traffic to 10.0.2.2 not permitted ]" So I have to start solving that problem. For the record, I am using Google Sign In with flutter with android emulator. It works well with production Google Sign In, but throws that error when I use the Firebase Emulator – Obum Mar 09 '22 at 23:39
  • @ObumunemeNwabude Google Sign In functionalities needs Google Services. I had to use my physical device for authentication, seems emulator doesn't have. – 4xMafole Mar 12 '22 at 06:21
  • 1
    Firebase Emulator does, but that is if it's called from a web only project. But with called from Flutter, yes it will use real Google Services. I solved the problem by adding the clearText permission in AndroidManifest in debug folder. And after signing in with Android Emulator or really device. Firebase will show the Google Account in the Firebase Emulator (which is what we want) – Obum Mar 13 '22 at 08:45
  • sorry please don't answer based on your assumption. that's misleading. it's not a warning because it throws FirebaseAuthException with the code "unknown" – stackunderflow May 07 '22 at 01:00
1

Your email would be signed in already. So be sure there is no same email in the Authentication users list.

In my situation, I've deleted the google account that I signed up for before.

0

Make sure that Email/Password auth is enabled as a Sign-in provider on Firebase Auth dashboard

Omatt
  • 8,564
  • 2
  • 42
  • 144