Skip to content

[πŸ›] Auth createUserWithEmailAndPassword always returns Cannot read property 'code' of undefined on AndroidΒ #8714

@thevishnupradeep

Description

@thevishnupradeep

Issue

Attempting to register a user using createUserWithEmailAndPassword within an expo application consistently results in a TypeError when accessing the code property of the caught error object, specifically: [TypeError: Cannot read property 'code' of undefined]. The problem only occurs on android and I can confirm that iOS works fine.

Describe your issue here


Project Files

Javascript

async registerUser(email: string, password: string) {
  try {
    const res = await createUserWithEmailAndPassword(getAuth(), email, password);
    console.log('Response @ ', res);
    return res;
  } catch (e) {
    console.log('error @ createUserWithEmailAndPassword: ', e);
    const error = e as FirebaseAuthTypes.NativeFirebaseAuthError;
    if (error.code === 'auth/invalid-email') {
      throw new Error('Invalid email address');
    }
    else if (error.code === 'auth/email-already-in-use') {
      throw new Error('Email address already in use. Try signing in.');
    }
    else if (error.code === 'auth/weak-password') {
      throw new Error('Password is too weak. Try a stronger password.');
    }
    else {
      throw new Error('An error occurred. Please try again later.');
    }
  }
}

package.json:

{
   "@react-native-firebase/analytics": "^23.4.0",
    "@react-native-firebase/app": "^23.4.0",
    "@react-native-firebase/app-check": "^23.4.0",
    "@react-native-firebase/auth": "^23.4.0",
    "@react-native-firebase/firestore": "^23.4.0",
    "@react-native-firebase/in-app-messaging": "^23.4.0",
    "@react-native-firebase/messaging": "^23.4.0",
    "@react-native-firebase/perf": "^23.4.0",
}

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • 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:
    • v23.4.0
  • Firebase module(s) you're using that has the issue:
    • Auth
  • Are you using TypeScript?
    • Y & 5.9.2


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions