skip to Main Content

I’m trying to create a sign-in form using flutter and firebase. I’m facing the following error while using the signInWithEmailAndPassword function:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/internal-error] An internal error has occurred, print and inspect the error details for more information.

Code:

body: Column(children: [
          TextField(
            controller: _email,
            keyboardType: TextInputType.emailAddress,
            enableSuggestions: false,
            autocorrect: false,
            decoration: const InputDecoration(
              border: OutlineInputBorder(), hintText: "Email"),
          ),
          TextField(
            controller: _password,
            obscureText: true,
            enableSuggestions: false,
            autocorrect: false,
            decoration: const InputDecoration(
              border: OutlineInputBorder(), hintText: "Password"),
          ),
          TextButton(
            onPressed: () async {
              final email = _email.text;
              final password = _password.text;
              await Firebase.initializeApp(
                options: DefaultFirebaseOptions.currentPlatform,
              );
              final userCredential = 
                await FirebaseAuth.instance.createUserWithEmailAndPassword(
                  email: email, password: password
                );
              print(userCredential);
            },
            child: const Text("Register"),
          )
        ])

I tried unrestricting my API keys from the Google Cloud Console, but that didn’t work. I’m using an IOS simulator. How can I solve this? Thanks in advance.

2

Answers


  1. Try to catch the error you get and print it! Then you probably get some more information. Maybe your input is incorrect.

    Try this:

    try {
      await FirebaseAuth.instance.signInWithEmailAndPassword(
        email: "[email protected]",
        password: "SuperSecretPassword!"
      );
    } on FirebaseAuthException catch  (e) {
      print('Failed with error code: ${e.code}');
      print(e.message);
    }
    

    https://firebase.google.com/docs/auth/flutter/errors

    Login or Signup to reply.
  2. do firebase intialization in the main function like this:

    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );
      runApp(const MyApp());
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search