Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [firebase_auth] signInWithEmailAndPassword returns error code "unknown" #10966

Closed
jayjay911 opened this issue May 15, 2023 · 25 comments · Fixed by #11258
Closed

🐛 [firebase_auth] signInWithEmailAndPassword returns error code "unknown" #10966

jayjay911 opened this issue May 15, 2023 · 25 comments · Fixed by #11258
Assignees
Labels
blocked: flutter platform: web Issues / PRs which are specifically for web. plugin: auth resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@jayjay911
Copy link

jayjay911 commented May 15, 2023

Bug report

Describe the bug
I am using Flutter Web and running in Chrome.

After upgrading to Flutter 3.10.0 and all my firebase dependencies I started getting unusual behaviour when attempting to sign into firebase with email and password.

Instead of throwing a FirebaseAuthMultiFactorException as expected, it throws a FirebaseAuthException with the following message:

An unknown error occurred: FirebaseError: Firebase: Proof of ownership of a second factor is required to complete sign-in. (auth/multi-factor-auth-required).

Error code is:

"unknown"

Error code is always "unknown" even in cases where email/password are incorrect.

Issue persists in a Flutter Demo Project with only firebase dependencies

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a Flutter Demo Project

  2. Add necessary code to initialise FirebaseApp

  3. Add the following to _incrementCounter() :

try {
      await FirebaseAuth.instance
          .signInWithEmailAndPassword(email: "email@domain.com", password: "password");
    } on FirebaseAuthMultiFactorException catch (e) {
      print(e.message);
      print(e.code);
      rethrow;
    } on FirebaseAuthException catch (e) {
      print(e.message);
      print(e.code);
      if (e.code == 'user-not-found') {
        print('The account does not exist');
      }
      if (e.code == 'second-factor-required') {
        print('Two factor challenge must be completed first');
      }
      if (e.code == 'multi-factor-auth-required') {
        print('Two factor challenge must be completed first');
      }
    }
  1. Add necessary dependencies to pubspec.yaml and call pub.get

Expected behavior

I am expecting a FirebaseAuthMultiFactorException where email and password are correct, otherwise a FirebaseAuthException with a code as before.

I need the FirebaseAuthMultiFactorException obviously so I can access the resolver, and I need the code in order to handle incorrect password, user does not exist etc cases.

Additional context

Running Flutter Web version in Chrome on M1 MacBook


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.0, on macOS 13.3.1 22E772610a darwin-arm64, locale en-ZA)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.77.3)
[✓] Connected device (2 available)
[✓] Network resources


Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
Dart SDK 3.0.0
Flutter SDK 3.10.0
testing 1.0.0+1

dependencies:
- cloud_firestore 4.7.0 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cupertino_icons 1.0.5
- firebase_analytics 10.4.0 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_app_check 0.1.4 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 4.6.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_auth_web 5.5.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta]
- firebase_core 2.12.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_database 10.2.0 [firebase_core firebase_core_platform_interface firebase_database_platform_interface firebase_database_web flutter]
- firebase_storage 11.2.0 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine]

dev dependencies:
- flutter_lints 2.0.1 [lints]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]

transitive dependencies:
- _flutterfire_internals 1.3.0 [collection firebase_core firebase_core_platform_interface flutter meta]
- async 2.11.0 [collection meta]
- boolean_selector 2.1.1 [source_span string_scanner]
- characters 1.3.0
- clock 1.1.1
- cloud_firestore_platform_interface 5.14.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 3.5.0 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.17.1
- fake_async 1.3.1 [clock collection]
- firebase_analytics_platform_interface 3.6.0 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.5.4 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_app_check_platform_interface 0.0.8 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_app_check_web 0.0.10 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_auth_platform_interface 6.15.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.5.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_database_platform_interface 0.2.5 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_database_web 0.2.3 [firebase_core firebase_core_web firebase_database_platform_interface flutter flutter_web_plugins js]
- firebase_storage_platform_interface 4.4.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.6.0 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- http 0.13.6 [async http_parser meta]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- js 0.6.7 [meta]
- lints 2.1.0
- matcher 0.12.15 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.2.0
- meta 1.9.1
- path 1.8.3
- plugin_platform_interface 2.1.4 [meta]
- sky_engine 0.0.99
- source_span 1.9.1 [collection path term_glyph]
- stack_trace 1.11.0 [path]
- stream_channel 2.1.1 [async]
- string_scanner 1.2.0 [source_span]
- term_glyph 1.2.1
- test_api 0.5.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.2 [collection]
- vector_math 2.1.4

@jayjay911 jayjay911 added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels May 15, 2023
@danagbemava-nc danagbemava-nc added the triage Issue is currently being triaged. label May 15, 2023
@danagbemava-nc
Copy link

Hi @jayjay911, how is your project setup on firebase? And can you provide a complete minimal reproducible code sample so that we can investigate this?

@danagbemava-nc danagbemava-nc added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels May 15, 2023
@jayjay911
Copy link
Author

jayjay911 commented May 15, 2023

Not sure what you need to know specifically about the Firebase project, there's a registered web app and I'm using the same configuration which has been working fine for over a year. Email and password sign in is enabled, along with SMS MFA.

The only change was client side ie upgrading Flutter to 3.10.0 and all the Firebase dependencies to support Dart 3. Then suddenly my Firebase sign in stopped working as it should.

Is the following sample of code enough or do you need a github project?

Added only the following dependencies to pubspec.yaml:

firebase_core: any
firebase_analytics: any
firebase_storage: any
cloud_firestore: any
firebase_database: any
firebase_auth: any
firebase_auth_web: any
firebase_app_check: any

Minimal Reproducible Code

Click To Expand
Future<FirebaseApp> initialize() async {
  // devConfig (FirebaseOptions) and developmentSiteKey kept private for obvious reasons.
  
  var app = await Firebase.initializeApp(options: devConfig);

  await FirebaseAppCheck.instance
      .activate(webRecaptchaSiteKey: developmentSiteKey);

  return app;
}

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  var _fbApp;
  _fbApp = initialize();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  var fbApp;
  MyApp({super.key, this.fbApp});

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: fbApp,
      builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            useMaterial3: true,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  Future<void> _incrementCounter() async {
    try {
      await FirebaseAuth.instance
          .signInWithEmailAndPassword(email: "email@domain.com", password: "password");
      // return "successful";
    } on FirebaseAuthMultiFactorException catch (e) {
      print(e.message);
      print(e.code);
      rethrow;
    } on FirebaseAuthException catch (e) {
      print(e.message);
      print(e.code);
      if (e.code == 'user-not-found') {
        print('The account does not exist');
      }
      if (e.code == 'second-factor-required') {
        print('Two factor challenge must be completed first');
      }
      if (e.code == 'multi-factor-auth-required') {
        print('Two factor challenge must be completed first');
      }
      // return e.code;
    }
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}


@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels May 15, 2023
@jayjay911
Copy link
Author

Downgrading Flutter back to version 3.7.12 and Dart back to version 2.19.6 immediately resolved the issue, error code is set and not "unknown" and the FirebaseAuthMultiFactorException is thrown properly.

So issue only occurs when I upgrade to Flutter 3.10.0 and Dart 3.

@danagbemava-nc danagbemava-nc changed the title 🐛 [firebase_auth] signInWithEmailAndPassword returns error code "unknown", does not throw FirebaseAuthMultiFactorException 🐛 [firebase_auth] signInWithEmailAndPassword returns error code "unknown" May 16, 2023
@danagbemava-nc
Copy link

Thanks for the details.

I can reproduce the error code being returned as unknown using the sample provided above on stable 3.10.0 but on stable 3.7.12, the error code is properly stated. I was only able to reproduce this on the web. My firebase project was not set up to use SMS MFA so the FirebaseAuthException block is what was always executed.

Labeling for further investigation

Running on flutter 3.7.12
🔥  To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".

An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:63011/jLprpnjAz0s=
The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:63011/jLprpnjAz0s=
FirebaseAuthException
The password is invalid or the user does not have a password.
wrong-password

Performing hot restart...                                        2,208ms
Restarted application in 2,210ms.
FirebaseAuthException
There is no user record corresponding to this identifier. The user may have been deleted.
user-not-found
The account does not exist
Running on flutter 3.10.0
A Dart VM Service on Chrome is available at: http://127.0.0.1:62231/ILEXAYtnLY0=
The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:62231/ILEXAYtnLY0=
FirebaseAuthException
An unknown error occurred: FirebaseError: Firebase: There is no user record corresponding to this identifier. The user may have been deleted. (auth/user-not-found).
unknown

Performing hot restart...                                          804ms
Restarted application in 809ms.
FirebaseAuthException
An unknown error occurred: FirebaseError: Firebase: The password is invalid or the user does not have a password. (auth/wrong-password).
unknown

@danagbemava-nc danagbemava-nc added plugin: auth platform: web Issues / PRs which are specifically for web. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels May 16, 2023
@russellwheatley russellwheatley self-assigned this May 16, 2023
@dotjon0
Copy link

dotjon0 commented May 19, 2023

any updates on this?

@ntherndon97
Copy link

This also affecting my app as well. Any updates would be great as to what is happening with this.

@jubnl
Copy link

jubnl commented May 31, 2023

Until this is fixed, here's a regex that will extract the code of a FirebaseAuthException from the exception message:

Note: This fix is temporary; as soon as a patch is deployed, we should use it.

String parseFirebaseAuthExceptionMessage({String plugin = "auth", required String? input}) {
  if (input == null) {
    return "unknown";
  }

  // https://regexr.com/7en3h
  String regexPattern = r'(?<=\(' + plugin + r'/)(.*?)(?=\)\.)';
  RegExp regExp = RegExp(regexPattern);
  Match? match = regExp.firstMatch(input);
  if (match != null) {
    return match.group(0)!;
  }

  return "unknown";
}

Usage:

try {
  // operation that might throw a FirebaseAuthException
} on FirebaseAuthException catch (e) {
  // change the plugin argument if needed
  // final code = parseFirebaseAuthExceptionMessage(input: e.message, plugin: "other");
  final code = parseFirebaseAuthExceptionMessage(input: e.message);
  if (code == "user-not-found") {
    // handle exception
  }
}

@agrimshar
Copy link

Yeah I'm getting the same issue.

@jperezr21
Copy link

Same issue here:

image

@Rajeet10
Copy link

Rajeet10 commented Jun 6, 2023

Could anybody tell me how to fix it now in the latest flutter version?

@hydev777
Copy link

Having the same problem here, all throw exception are coming unknown.

@mdryankov
Copy link

As a temporary workaround I just downgraded Flutter sdk to 3.7.9. Works fine. Hope the issue would be fix for the latest version at some point.

@kNoAPP
Copy link

kNoAPP commented Jun 16, 2023

This is impacting my project as well. Running firebase_auth v4.6.2. This code used to work, but has since stopped being functional due to bad parsing internal to the firebase_auth library.

From my debugging session:
I purposely entered a correct email, but wrong password into a cloud Firebase Auth instance. Notice that while the FirebaseError contains all the correct/expected information, the debugger object does not. It doesn't appear to correctly parse this information out of the message.

DEBUG from VSC:

FirebaseAuthException ([firebase_auth/unknown] An unknown error occurred: FirebaseError: Firebase: The password is invalid or the user does not have a password. (auth/wrong-password).)


code: "unknown"
credential: null
email: null
message: "An unknown error occurred: FirebaseError: Firebase: The password is invalid or the user does not have a password. (auth/wrong-password)."
phoneNumber: null
plugin: "firebase_auth"
stackTrace: null
tenantId: null

SCREENSHOT:
Screenshot 2023-06-16 081944

@dotjon0
Copy link

dotjon0 commented Jun 16, 2023

We've also had big problems with Firebase Auth being compatible with the latest version of Flutter. We do not understand why a Google Flutter release has been made and with the Google Firebase suite being left behind and not compatible, and with no resolution in weeks... Is Firebase not important as part of Google's strategy around Flutter... It would also be good if the Flutter Firebase suite was written purely in dart, end-to-end as the warning messages in the terminal due to Firebase Core is a really bad developer experience, with hours of research/resolution needed to fix - to such a degree that Andrea has very kindly written a long article to help people with this https://codewithandrea.com/articles/flutter-firebase-flutterfire-cli/

michasng added a commit to michasng/gestures that referenced this issue Jun 18, 2023
@Guetti
Copy link

Guetti commented Jun 22, 2023

I have the same issue.
It seems that only happens in web apps. I tested an android app that i have but as a web app and throw the same problem.

@RaphaelRat
Copy link

RaphaelRat commented Jun 24, 2023

I also have the same issue, but the regex by @jubnl helps a lot. And it is only in debug mode, when I host my flutter web page on firebase or github, it works correctly, so I set a conditional for choose between regex and the correct form if I'm on release mode or not

@abderrahmen13
Copy link

abderrahmen13 commented Jun 26, 2023

is that because ou must update the phone number for the user first ?

@sarmuelThee
Copy link

hello, i am trying to do this exact thing in flutter flow (creating an authentication custom action ) and it throws the same kind of errors for me too, is there ant work around?

MarbertMataverde added a commit to MarbertMataverde/academix that referenced this issue Jul 8, 2023
There was a bug where the signInWithEmailAndPassword method in firebase_auth package was returning an error code as "unknown". This issue was reported in the GitHub repository of FlutterFire: firebase/flutterfire/issues/10966.

To address this issue, a temporary fix has been implemented by using the parseFirebaseAuthExceptionMessage function. This function uses a regex pattern to extract the error code from the FirebaseAuthException's exception message.

The fix ensures that the actual error code is properly extracted and handled, providing more accurate error information during the sign-in process.

Note: This is a temporary fix until the underlying issue is resolved in the firebase_auth package.
MarbertMataverde added a commit to MarbertMataverde/academix that referenced this issue Jul 8, 2023
The signIn function has been updated to handle Firebase authentication errors more effectively. This refactor addresses a bug where signInWithEmailAndPassword was returning an error code as "unknown" (GitHub issue: firebase/flutterfire/issues/10966).

To address this issue, a temporary fix has been implemented using the parseFirebaseAuthExceptionMessage function. This function extracts the error code from the FirebaseAuthException's exception message using a regular expression.

The new code includes a switch statement to handle specific error codes such as "wrong-password", "user-not-found", "user-disabled", "too-many-requests", and "network-request-failed". Each error code is associated with a customDialogBox that displays an appropriate error message.

In case an unknown error code is encountered, the customDialogBox displays the code itself temporarily, along with the error message.

Additionally, a catch block has been added to handle any other errors that may occur during the sign-in process.

These changes improve the error handling and provide more informative error messages to the user in case of authentication failures.
@anjogithub
Copy link

anjogithub commented Jul 10, 2023

is there any updates on this bug? also encountered this error. I also need the FirebaseAuthMultiFactorExceptionto be able to access the resolver.

@anjogithub
Copy link

i tried updating my flutter version and firebas euth to latest versions, the error still occurs. Hopefully it would be fixed on next updates of firebase auth plugin.
Any updates on this error/bug on web?

@Shawn-sudo
Copy link

I'm experiencing a somewhat similar issue on iOS. This issue might not be limited to web only.

Screenshot 2023-07-17 at 9 38 50 PM

One thing different from you guys is that I see a weird code starting with 0x instead of a friendly error message.

@anjogithub
Copy link

I am stuck on this error. Can't proceed to completeley implement Firebase MFA.
It almost 2 weeks now that i encountered this.
Badly needed a fix for this.

@anjogithub
Copy link

if i may ask, how can we apply the fix? will this fix be included in the next updates of firebase_auth?

@danagbemava-nc danagbemava-nc added the resolution: fixed A fix has been merged or is pending merge from a PR. label Jul 25, 2023
@russellwheatley
Copy link
Member

@anjogithub - will be out in the next release at some point today 👍

@papiqo
Copy link

papiqo commented Aug 20, 2023

i got the same problem, i changed it to get_user_by_email, i can get uid, but my app can't use authentication

@firebase firebase locked and limited conversation to collaborators Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: flutter platform: web Issues / PRs which are specifically for web. plugin: auth resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.