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

[🐛] 🔥 createUserWithEmailAndPassword returns wrong error code #8359

Open
3 of 7 tasks
LielAmar opened this issue Feb 21, 2025 · 3 comments
Open
3 of 7 tasks

[🐛] 🔥 createUserWithEmailAndPassword returns wrong error code #8359

LielAmar opened this issue Feb 21, 2025 · 3 comments
Labels

Comments

@LielAmar
Copy link

LielAmar commented Feb 21, 2025

🔥

Issue

When creating a firebase project, configuring it, adding a billing account, upgrading the plane to Blaz, setting up email/password as a sign-in options, and then enabling password policy (for example, requiring upper/lower characters and numbers), then calling createUserWithEmailAndPassword with a valid email and a password that doesn't follow all the password-policy requirements returns internal-error instead of password-does-not-meet-requirements (I tested the same firebase project with the js firebase package and there I do get password-does-not-meet-requirements).

const handleSignUp = async (
  email: string,
  password: string,
) => {
  if (!email || !password) {
    throw new Error("Please enter a valid email and password");
  }

  const response = await auth.createUserWithEmailAndPassword(email, password);

  if (!response || !response.user) {
    throw new Error("Something went wrong while creating user");
  }

  return response.user;
};
handleSignUp(email, password)
      .then(() => {
        console.debug("Sign up successful! Redirecting to (app)...");
        router.replace("/(app)");
      })
      .catch((error: ReactNativeFirebase.NativeFirebaseError) => {
        console.error(error); // prints [auth/internal-error] An internal error has occurred, please try again.
        console.error(error.code); // prints auth/internal-error
      });

handleSignUp('test@email.com', 'thispassworddoesnthavedigits');

in a plain js project:

import { initializeApp } from 'firebase/app';
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";

const firebaseConfig = {
...
};

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);

const main = async () => {
  createUserWithEmailAndPassword(auth, 'test@email.com', 'thispassworddoesnthavedigits')
  .then((userCredential) => {
    console.log('success', userCredential);
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;
    console.log('error', errorCode, errorMessage); // prints 'password-does-not-meet-requirements'
  });
  
  console.log(auth);
}

main();

I upgraded the project to Blaze as many said it causes similar issues. I re-downloaded both the Android and ios configuration files from the Firebase dashboard, I made sure everything was correct. Everything else works fine - both registration and authentication.


Project Files

Nothing special, just a plain expo project (of course I'm using development builds with expo-dev-client).

Image

Javascript

Click To Expand

package.json:

{
"name": "...",
"main": "expo-router/entry",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"test": "jest --watchAll",
"lint": "expo lint",
"build-ios": "expo run:ios",
"build-android": "expo run:android"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@expo-google-fonts/rubik": "^0.2.3",
"@expo/vector-icons": "^14.0.2",
"@react-native-community/datetimepicker": "8.2.0",
"@react-native-firebase/app": "^21.10.1",
"@react-native-firebase/auth": "^21.10.1",
"@react-native-firebase/crashlytics": "^21.10.1",
"@react-navigation/bottom-tabs": "^7.2.0",
"@react-navigation/native": "^7.0.14",
"expo": "~52.0.33",
"expo-auth-session": "^6.0.3",
"expo-blur": "~14.0.3",
"expo-build-properties": "~0.13.2",
"expo-constants": "~17.0.6",
"expo-dev-client": "~5.0.12",
"expo-haptics": "~14.0.1",
"expo-image": "~2.0.5",
"expo-linking": "~7.0.5",
"expo-localization": "~16.0.1",
"expo-router": "~4.0.17",
"expo-secure-store": "^14.0.1",
"expo-splash-screen": "~0.29.21",
"expo-status-bar": "~2.0.1",
"expo-symbols": "~0.2.2",
"expo-system-ui": "~4.0.8",
"expo-web-browser": "~14.0.2",
"nativewind": "^4.1.23",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-native": "0.76.7",
"react-native-gesture-handler": "~2.20.2",
"react-native-keyboard-controller": "^1.16.4",
"react-native-modal-datetime-picker": "^18.0.0",
"react-native-reanimated": "3.16.2",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "~4.4.0",
"react-native-toast-message": "^2.2.1",
"react-native-web": "~0.19.13",
"react-native-webview": "13.12.5",
"tailwindcss": "^3.4.17"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@types/jest": "^29.5.12",
"@types/react": "~18.3.12",
"babel-plugin-transform-remove-console": "^6.9.4",
"jest": "^29.2.1",
"jest-expo": "~52.0.3",
"typescript": "^5.3.3"
}
}

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")

require 'json'
podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {}

ENV['RCT_NEW_ARCH_ENABLED'] = podfile_properties['newArchEnabled'] == 'true' ? '1' : '0'
ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] = podfile_properties['EX_DEV_CLIENT_NETWORK_INSPECTOR']

platform :ios, podfile_properties['ios.deploymentTarget'] || '15.1'
install! 'cocoapods',
  :deterministic_uuids => false

prepare_react_native_project!

target '...' do
  use_expo_modules!

  if ENV['EXPO_USE_COMMUNITY_AUTOLINKING'] == '1'
    config_command = ['node', '-e', "process.argv=['', '', 'config'];require('@react-native-community/cli').run()"];
  else
    config_command = [
      'node',
      '--no-warnings',
      '--eval',
      'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
      'react-native-config',
      '--json',
      '--platform',
      'ios'
    ]
  end

  config = use_native_modules!(config_command)

  use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
  use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS']

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => podfile_properties['expo.jsEngine'] == nil || podfile_properties['expo.jsEngine'] == 'hermes',
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/..",
    :privacy_file_aggregation_enabled => podfile_properties['apple.privacyManifestAggregationEnabled'] != 'false',
  )

  post_install do |installer|
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      :ccache_enabled => podfile_properties['apple.ccacheEnabled'] == 'true',
    )

    # This is necessary for Xcode 14, because it signs resource bundles by default
    # when building for devices.
    installer.target_installation_results.pod_target_installation_results
      .each do |pod_name, target_installation_result|
      target_installation_result.resource_bundle_targets.each do |resource_bundle_target|
        resource_bundle_target.build_configurations.each do |config|
          config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
        end
      end
    end
  end
end

Environment

Click To Expand

  • Platform that you're experiencing the issue on:
    • 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:
    • 21.10.1
  • Firebase module(s) you're using that has the issue:
    • auth
  • Are you using TypeScript?
    • Yes & 5.3.3


@mikehardy
Copy link
Collaborator

Interesting - looks like a gap here

On native I don't that error code exists, but I'm not 100% - usually with an internal error there is more information in device logs, have you looked at those to see all the information? It may be the code is in there just buried + not passed through

However it looks like the pattern on native is to call validatePassword first and then respond based on the return value there

Unfortunately, that (an implementation of validatePassword) is a gap here! We don't have that implemented.

Looks easy enough to do we just haven't - this was brought up quite recently in a Discussion here as well #8328

Definite thing to do: put together an implementation of validatePassword here - would love a PR for that if you have time, looks like one of the easier PRs ever here as it is an easy JS API, should just call right through to native, and the two native parts should also be the most trivial wrappers to the underlying SDKs - with other parts of the native modules being useful as templates to set the method signatures / do the call / return the result

Possible thing to do - based on results of looking at current error in device logs: pass through the correct code if we can, based on whatever is in the error now

@LielAmar
Copy link
Author

LielAmar commented Feb 21, 2025

Hey Mike, thanks for the quick response!

I looked into the device logs but couldn't find anything useful there (well, at least nothing related to firebase auth that has anything to do with error codes, and more specifically the password-does-not-meet-requirements error code).

As for validatePassword - as much as I'd love to contribute and help, I am fairly new to React Native and unfamiliar with native development overall. So I think I will leave this easy PR to someone else! :)

@marcel-happyfloat
Copy link

Just upgraded my project and run into the same issues, wrong error code / no validatePassword method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants