firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.85k stars 893 forks source link

Using createUserWithEmailAndPassword returns a NULL user / currentUser but user is created successfully! #4935

Closed asalha closed 3 years ago

asalha commented 3 years ago

[REQUIRED] Describe your environment

Expo, managed flow.

{ "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", "eject": "expo eject" }, "dependencies": { "@react-native-async-storage/async-storage": "^1.15.4", "@react-native-community/masked-view": "0.1.10", "@react-native-community/netinfo": "^6.0.0", "@react-navigation/bottom-tabs": "^5.11.11", "@react-navigation/native": "^5.9.4", "@react-navigation/stack": "^5.14.4", "expo": "~41.0.1", "expo-firebase-analytics": "~4.0.2", "expo-font": "~9.1.0", "expo-image-picker": "~10.1.4", "expo-location": "~12.0.4", "expo-secure-store": "^10.1.0", "expo-status-bar": "~1.0.4", "firebase": "^8.2.3", "react": "16.13.1", "react-dom": "16.13.1", "react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz", "react-native-confirmation-code-field": "^7.1.0", "react-native-dropdown-picker": "^5.1.16", "react-native-elements": "^3.4.1", "react-native-geocoding": "^0.5.0", "react-native-gesture-handler": "~1.10.2", "react-native-maps": "^0.27.1", "react-native-popup-menu": "^0.15.10", "react-native-reanimated": "~2.1.0", "react-native-safe-area-context": "3.2.0", "react-native-screens": "~3.0.0", "react-native-toast-message": "^1.4.9" }, "devDependencies": { "@babel/core": "^7.14.3", "@types/react": "~16.9.35", "@types/react-native": "~0.63.2", "@typescript-eslint/eslint-plugin": "^4.24.0", "@typescript-eslint/parser": "^4.24.0", "eslint": "^7.27.0", "eslint-plugin-react": "^7.23.2", "eslint-plugin-react-hooks": "^4.2.0", "typescript": "^4.2.4" }, "private": true }

[REQUIRED] Describe the problem

Upon user creation with email and password, the returned user is NULL and NO error message thrown! However, when checking the backend, the user is created successfully.

Relevant Code:

In the code below, "User credentials" and "currentUser" are both undefined and null respectively. I tried using firebase.auth().onAuthStateChanged, same result, the returned user is NULL.

User credentials: Object { "additionalUserInfo": wg { "isNewUser": true, "providerId": "password", }, "credential": null, "operationType": "signIn", "user": null, }


try {
  await firebase.default
    .auth()
    .createUserWithEmailAndPassword(email, password)
    .then((userCredential) => {
      console.log(
        "User credentials:",
        userCredential.user,
        "Current user:",
        firebase.default.auth().currentUser
      );
    })
    .catch((error) => {
      console.error("Error adding user:", error.code, error.message);
    });
} catch (err) {
  console.log(err);
}
asalha commented 3 years ago

My mistake. Sorry about that!