invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.54k stars 2.19k forks source link

[🐛] [auth/internal-error] Errors not to be handled properly for signInWithEmailAndPassword #7433

Open maximownrock opened 8 months ago

maximownrock commented 8 months ago

Issue

I'm experiencing an issue. When I call signInWithEmailAndPassword with valid credentials, everything works fine, and the user is successfully authenticated. However, if I input incorrect credentials, instead of getting error codes like 'auth/user-not-found' or 'auth/wrong-password' or something similar, I receive 'auth/internal-error' with the message [Error: [auth/internal-error] An internal error has occurred, please try again.]

The most interesting part is that for the createUserWithEmailAndPassword function, everything works perfectly. Errors are handled correctly, and the user is created. I can't figure out what's causing the errors not to be handled properly for signInWithEmailAndPassword. Has anyone else encountered this issue?


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "Project", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "lint": "eslint --ext .js,.ts,.tsx src", "lint-fix": "eslint --ext .js,.ts,.tsx src --fix", "start": "react-native start", "test": "jest" }, "pre-commit": [ "lint" ], "dependencies": { "@react-native-async-storage/async-storage": "^1.19.3", "@react-native-firebase/analytics": "^18.6.1", "@react-native-firebase/app": "^18.6.1", "@react-native-firebase/auth": "^18.6.1", "@react-native-firebase/crashlytics": "^18.6.1", "@react-navigation/bottom-tabs": "^6.5.11", "@react-navigation/native": "^6.1.9", "@react-navigation/stack": "^6.3.20", "@reduxjs/toolkit": "^1.9.7", "axios": "^1.5.1", "axios-case-converter": "^1.1.0", "formik": "^2.4.5", "i18next": "^23.6.0", "react": "18.2.0", "react-i18next": "^13.3.1", "react-native": "0.72.6", "react-native-gesture-handler": "^2.13.4", "react-native-linear-gradient": "^2.8.3", "react-native-rate": "^1.2.12", "react-native-safe-area-context": "^4.7.4", "react-native-screens": "^3.27.0", "react-native-svg": "^13.14.0", "react-redux": "^8.1.3", "redux-persist": "^6.0.0", "redux-persist-transform-filter": "^0.0.22", "redux-saga": "^1.2.3", "yup": "^1.3.2" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/plugin-proposal-private-methods": "^7.18.6", "@babel/plugin-transform-flow-strip-types": "^7.22.5", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/eslint-config": "^0.72.2", "@react-native/metro-config": "^0.72.11", "@tsconfig/react-native": "^3.0.0", "@types/react": "^18.0.24", "@types/react-test-renderer": "^18.0.0", "@types/redux-persist": "^4.3.1", "@typescript-eslint/eslint-plugin": "^6.8.0", "@typescript-eslint/parser": "^6.8.0", "babel-jest": "^29.2.1", "babel-plugin-module-resolver": "^5.0.0", "eslint": "^8.19.0", "eslint-plugin-jest": "^27.4.3", "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-native": "^4.1.0", "eslint-plugin-simple-import-sort": "^10.0.0", "jest": "^29.2.1", "metro-react-native-babel-preset": "0.76.8", "pre-commit": "^1.2.2", "prettier": "^3.0.3", "react-native-svg-transformer": "^1.1.0", "react-test-renderer": "18.2.0", "typescript": "4.8.4" }, "engines": { "node": ">=16" } } ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "crashlytics_debug_enabled": false, "crashlytics_disable_auto_disabler": true, "crashlytics_auto_collection_enabled": true, "crashlytics_is_error_generation_on_js_crash_enabled": true, "crashlytics_javascript_exception_handler_chaining_enabled": false, "google_analytics_automatic_screen_reporting_enabled": false } } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # Resolve react_native_pods.rb with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', 'require.resolve( "react-native/scripts/react_native_pods.rb", {paths: [process.argv[1]]}, )', __dir__]).strip platform :ios, min_ios_version_supported prepare_react_native_project! # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set. # because `react-native-flipper` depends on (FlipperKit,...) that will be excluded # # To fix this you can also exclude `react-native-flipper` using a `react-native.config.js` # ```js # module.exports = { # dependencies: { # ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}), # ``` flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled linkage = ENV['USE_FRAMEWORKS'] if linkage != nil Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green use_frameworks! :linkage => linkage.to_sym end $RNFirebaseAsStaticFramework = true target 'Artnership' do use_frameworks! :linkage => :static config = use_native_modules! # Flags change depending on the env values. flags = get_default_flags() use_react_native!( :path => config[:reactNativePath], # Hermes is now enabled by default. Disable by setting this flag to false. :hermes_enabled => flags[:hermes_enabled], :fabric_enabled => flags[:fabric_enabled], # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable the next line. # :flipper_configuration => flipper_config, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) target 'ArtnershipTests' do inherit! :complete # Pods for testing end post_install do |installer| # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 react_native_post_install( installer, config[:reactNativePath], :mac_catalyst_enabled => false ) __apply_Xcode_12_5_M1_post_install_workaround(installer) end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; self.moduleName = @"Artnership"; // You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } @end ```

Environment

Click To Expand

**`react-native info` output:** ``` OUTPUT GOES HERE ``` - **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `^18.6.1` - **`Firebase` module(s) you're using that has the issue:** - `@react-native-firebase/auth` - **Are you using `TypeScript`?** - `YES` & `4.8.4`


mikehardy commented 8 months ago

Interesting - you should run this from Xcode on a real device and watch the console output, an internal error usually indicates that the firebase-ios-sdk will spit out some information that can be helpful in troubleshooting, before it is mostly discarded and just bubbles up as "internal error"

maximownrock commented 8 months ago

@mikehardy I'll do it and come back here with the answers

ZaharenkoNickInterexy commented 8 months ago

Similar problem. tell me, did you manage to solve it?

crasneanucristian commented 7 months ago

I have the same problem as @maximownrock when I run the app on simulator or a real device. react-native-firebase: ^18.6.1

maximownrock commented 7 months ago

Hello everyone, I haven't found a solution

Nantris commented 7 months ago

I just started up our Android app with React Native Firebase for the first time using signInWithEmailAndPassword, but when I attempt to sign in nothing happens. No error, no indication anything is occurring. This in on 18.5.0.

I'm currently upgrading to 18.6.2 but based on the changelog and this issue being open I don't expect it will help.

Even looking at the raw device logs yields no clues.

Can anyone comment on what might be going wrong here or how we might help to troubleshoot?

Edit: 18.6.2, same issue.

ZaharenkoNickInterexy commented 7 months ago

@Slapbox I don't think the problem has anything to do with this topic. Perhaps you have a catch block somewhere where the authentication error is flying away, so you don't see it

ZaharenkoNickInterexy commented 7 months ago

@mikehardy Perhaps you need more information about our issue? In my case the problem is reproduced on both emulator and real IOS device, in both prod and dev modes. Maybe you can suggest how to get more information about the error. I think the problem may have something to do with firebase configuration, as I used to get correct error statuses for incorrectly entered data, but after some time I started getting auth/internal-error instead of auth/wrong-password and other errors.

mikehardy commented 7 months ago

@Slapbox please don't thread hijack, and for the second time in a couple seconds --> https://stackoverflow.com/help/how-to-ask

@ZaharenkoNickInterexy my comment above is where I've left this, haven't seen any information provided that addresses it:

Interesting - you should run this from Xcode on a real device and watch the console output, an internal error usually indicates that the firebase-ios-sdk will spit out some information that can be helpful in troubleshooting, before it is mostly discarded and just bubbles up as "internal error"

Nantris commented 7 months ago

I'm sorry, I misread the issue text. Didn't mean to hijack. I didn't realize it was working with valid credentials.

Sorry - I commented here because I believe it was related.

If OP had had those symptoms on Android I would assume my issue was separate, but since they're having them on iOS I suspected it could be a difference in how (and if) the error is shown.


Perhaps you have a catch block somewhere where the authentication error is flying away, so you don't see it

Maybe, but why would it only occur when we move to react-native-firebase? Our auth errors were always properly thrown and caught when using the JS SDK.

mikehardy commented 7 months ago

@Slapbox you may have a real thing here - I would lean towards you having discovered some fidelity error between our behavior and the behavior in firebase-js-sdk - if you open a fresh issue we can explore it

Nantris commented 7 months ago

I apologize for the issue noise. As I was filing a new issue, I found I overlooked a tiny error much higher up in the console: forceWebSockets() is not implemented. Removing our call to that unimplemented function allows login to proceed as expected.

Always fun when the proper debugger won't load and you're left skimming the CLI.


So next I tried to reproduce the issue OP reported on Android, but I get the expected 'auth/user-not-found' - so this problem may be iOS-specific.

Unfortunately I'm a while from being able to test it on iOS on our end.

mikehardy commented 7 months ago

@Slapbox is that this API? https://firebase.google.com/docs/reference/js/database#forcewebsockets ? If we're missing APIs please feel free to open a "missing firebase-js-sdk API" issue and post them all up there. They may not have more than stub implementations here but we do have the goal of being a drop-in API-for-API replacement for firebase-js-sdk and I haven't done an audit yet on the modular / v9 API of firebase-js-sdk yet. An issue with a list of already-known ones would get us started

ZaharenkoNickInterexy commented 7 months ago

@mikehardy I'm getting this error. The error is reproduced on a real device, the application is built from xcode [Error: [auth/internal-error] An internal error has occurred, please try again.]

mikehardy commented 7 months ago

@ZaharenkoNickInterexy please note this part of my comment especially:

watch the console output, an internal error usually indicates that the firebase-ios-sdk will spit out some information that can be helpful in troubleshooting

Was there nothing else in Console.app as this happened? No other information at all? I was really hoping for more 🤔

AkhmetovAitzhan commented 7 months ago

@maximownrock "if I input incorrect credentials, instead of getting error codes like 'auth/user-not-found' or 'auth/wrong-password' or something similar, I receive 'auth/internal-error'" this happens because of enabled "Email enumeration protection" in your firebase project>Authentication>Settings>User Actions. Source: https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection.

ZaharenkoNickInterexy commented 7 months ago

@AkhmetovAitzhan @mikehardy Indeed, disabling this helped, but is it the right thing to do. Judging by firebase documentation, this option should not affect error statuses during authorisation. Is it correct, or have I misunderstood something?

Nantris commented 7 months ago

Here's a corrected link: https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection

From the link:

Invalid sign-in cases return an INVALID_LOGIN_CREDENTIALS error response. Invalid sign-up cases continue to return EMAIL_EXISTS errors

I think INVALID_LOGIN_CREDENTIALS is different than the default incorrect/non-existent email message. I wonder if React Native Firebase fails to handle it under the hood?


Judging by firebase documentation, this option should not affect error statuses during authorisation.

It sounds to me like that's actually exactly what it should do. It's obfuscating the existence of user accounts to prevent brute force attacks.

mikehardy commented 7 months ago

@Slapbox - I think INVALID_LOGIN_CREDENTIALS is different than the default incorrect/non-existent email message. I wonder if React Native Firebase fails to handle it under the hood? - perhaps, you can see the error code mappings in the respective native files (locating those quickly with a repo search on github web UI)

@AkhmetovAitzhan that's a great find! It would probably help quite a few people if you could hit the edit button at the top right of any of the web pages where it seemed important (perhaps the reference page for the APIs in question?) and add this as a note

Nantris commented 7 months ago

It seems likely this is the mapping, and if so it seems correct: https://github.com/invertase/react-native-firebase/blob/f8b7794db23185c8a934a3e3623e996ce282c1f7/packages/auth/ios/RNFBAuth/RNFBAuthModule.h#L29

But maybe I'm misinterpreting.

mikehardy commented 7 months ago

Those are the iOS mappings, and they do look correct :thinking: - and there are separate ones for invalid email / wrong password - I suppose for those that haven't restricted the error to be just "invalid credentials"

https://github.com/invertase/react-native-firebase/blob/f8b7794db23185c8a934a3e3623e996ce282c1f7/packages/auth/ios/RNFBAuth/RNFBAuthModule.h#L29-L34

github-actions[bot] commented 6 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

Peetee06 commented 6 months ago

I just ran into the same issue where I used the following snippet:

final credential = EmailAuthProvider.credential(
  email: email,
  password: password,
);
await currentUser.reauthenticateWithCredential(credential);

I used an invalid password to test this. On android I get the expected error code of invalid_credential. On iOS I get internal-error. This is the Xcode console output:

Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> resuming, timeouts(60.0, 604800.0) QOS(0x19) Voucher (null)
[Telemetry]: Activity <nw_activity 12:2[9C93AC45-D0EC-42A5-8908-078ABFFBC6D3] (reporting strategy default)> on Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> was not selected for reporting
Connection 0: creating secure tcp or quic connection
Connection 61: enabling TLS
Connection 61: starting, TC(0x0)
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> setting up Connection 61
Connection 61: asked to evaluate TLS Trust
[TLSCBQ] Need to invoke to satisfy trust callback
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> auth completion disp=0 cred=0x2894eaeb0
System Trust Evaluation yielded status(0)
Connection 61: TLS Trust result 0
Connection 61: connected successfully
Connection 61: TLS handshake complete
Connection 61: ready C(N) E(N)
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> done setting up Connection 61
Connection 61: set is idle false
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> now using Connection 61
Connection 61: received viability advisory(Y)
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> sent request, body S 145
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> received response, status 400 content K
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> done using Connection 61
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> response ended
Connection 61: set is idle true
HTTP/2 Connection 61 Stream 1 ended successfully true
Task <FBC18053-21A6-4984-BAEB-DEEC09E87D52>.<1> finished successfully
Connection 61: cleaning up
Connection 61: done
Garbage collection for alternative services
flutter: \^[[38;5;199m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;199m│ [firebase_auth/internal-error] An internal error has occurred, print and inspect the error details for more information.<…>
[stack trace of the error in my app]

Is there any other information that I can supply which would help resolve this issue?

mikehardy commented 6 months ago

@Peetee06

flutter:

You are in the react-native-firebase repository 🤔

Regardless, nothing in the provided log snippet looks conclusively related to the error message either being actually internal with some SDK issue from firebase-ios-sdk (or flutter's firebase auth code) or just mapped incorrectly. So I'm not sure what to say there

Peetee06 commented 6 months ago

@mikehardy you are right, I just realized that when looking at the notification I got for your answer. 😅

Will also post this in the correct repo, but nevertheless it seemed like the same issue.

Thank you for your response!

github-actions[bot] commented 5 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

Nantris commented 5 months ago

@maximownrock @ZaharenkoNickInterexy @crasneanucristian did any of you have success resolving this? I'd like to enable the enumeration feature that I believe causes this in our project but I haven't had a chance to test yet.

The correct error this should return should be akin to INVALID_LOGIN_CREDENTIALS according to the Firebase docs.

Furthermore I never did find the Android mappings to see if they appear correct. Is it in this file, but just organized differently? But the messages are different too so I don't know: https://github.com/invertase/react-native-firebase/blob/f8b7794db23185c8a934a3e3623e996ce282c1f7/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java

github-actions[bot] commented 4 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

amcoolkid commented 4 months ago

This continue to be an issue, why cannot the lib pass down the right exception/error (on iOS, which is what I tested and observed) Everything seems goes into a internal-error Error. Please help.

github-actions[bot] commented 3 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

mikehardy commented 2 months ago

I can reopen this as it appears to still be an issue, but please note that "please help" could be rewritten in an open source context as "I will investigate this further and post a PR when I can" - we all need to help each other and ourselves in other words.

There may be some error code mapping issues internally - any fixes would be most welcome

usman-whizpool commented 1 month ago

I am also facing same issue. same app code works fine for android, while for iOS case it fails with this error. double checked googleservice plist file. bundle id .

usman-whizpool commented 1 month ago

for me it was permission issue on google console. Firebase auto created api key was somehow edited and required permissions for firebase auth, token and other were missing. reseting it to default has resolve this issue

EmanuilM commented 4 weeks ago

for me it was permission issue on google console. Firebase auto created api key was somehow edited and required permissions for firebase auth, token and other were missing. reseting it to default has resolve this issue

Where exactly in the console can I find these permissions, and which one have you changed?

minhchienwikipedia commented 3 weeks ago

Any solution? I just got this issue recently

tux2nicolae commented 2 weeks ago

I get the same error when calling verifyPhoneNumber()