firebase / firebase-js-sdk

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

Firebase SignUp with Email/Password failing validating credentials #7832

Closed butri71 closed 11 months ago

butri71 commented 11 months ago

Operating System

react native 0.71.14 - expo sdk 48 - Node JS v18.17.1

Browser Version

Using iPhone 13Pro as testing device on Expo Go app

Firebase SDK Version

9.21.0

Firebase SDK Product:

Auth

Describe your project's tooling

React Native app using Expo managed service. Firebase Authentication by SignUp with Email and Password to read/write data on Firebase Realtime Database

Describe the problem

I've been using the following same code setup for the past 2 years without a single issue. I use the firebase/auth library to authenticate the user to access data stored in Realtime Database and then carry out my usual read/write operation.

When trying to authenticate the user using signInWithEmailAndPassword I get an error Cannot read property 'then' of undefined

The problem appeared the first time 20 hours ago since posting this issue here. It started intermittently and then it completely stopped working. I'm using the same authentication functionality across my code in various functions and it fails everywhere therefore not related issue on specific function.

The username and password are correctly passed and validated and showing correctly in console.log and I believe the issue is around the auth parameter

Steps and code to reproduce issue

1) firebase.js is the firebase config files 2) main.js is a typical function that I call to write a new post rating into my Realtime Database. 3) When I call addRating I try first to authenticate my user in firebase before submitting a change 4) The usual signInWithEmailAndPassword now fails on auth

// firebase.js

import { initializeApp } from 'firebase/app';
import { getDatabase } from 'firebase/database';
import { getAuth } from 'firebase/auth';

const firebaseConfig = {
  apiKey: "********",
  authDomain: "********",
  databaseURL: "********",
  projectId: "********",
  storageBucket: "********",
  messagingSenderId: "********",
  appId: "********",
  measurementId: "********",
};

const app = initializeApp(firebaseConfig); 
 export const auth = getAuth();
 export const db = getDatabase();
 export const email = "********",
 export const password = "********",

// main.js - example function where I use firebase auth 
import { signInWithEmailAndPassword, onAuthStateChanged } from "firebase/auth";
import { auth, db, email, password } from "../../util/firebase";

const addRating = async (  id, rating  ) => { 
    await signInWithEmailAndPassword(auth, email, password)
    console.log('auth: ',auth)
    console.log('email: ',email)
    console.log('password: ',password)

   .then((userCredential) => {     
        console.log('userCredential: ',userCredential)
        const user = userCredential.user;             
    })
    .catch((error) => {
        const errorCode = error.code;
        const errorMessage = error.message;
        console.log("addReviewRequest failing to log to firebase with: " + errorCode + " - " + errorMessage);
    });

Error: Cannot read property 'then' of undefined

The logs are showing the following:

LOG: auth:  {"apiKey": "**********", "appName": "[DEFAULT]", "authDomain": "*********", "currentUser": {"_redirectEventId": undefined, "apiKey": "********", "appName": "[DEFAULT]", "createdAt": "1607606241646", "displayName": undefined, "email": "*********", "emailVerified": false, "isAnonymous": false, "lastLoginAt": "1701525810098", "phoneNumber": undefined, "photoURL": undefined, "providerData": [Array], "stsTokenManager": [Object], "tenantId": undefined, "uid": "*******"}}
 LOG  email:  *********
 LOG  password:  *********

Whenever I use * it means it's returning the correct values as expected, just masking sensitive data. My understanding that the failures point is in .then((userCredential) in fact it doesn't go any further in showing the console.log('userCredential: ',userCredential)

Basically userCredential is now undefined every time for some reason.

butri71 commented 11 months ago

Closing this since problem is not occurring any more since this morning

DellaBitta commented 11 months ago

This seems like a syntax error to me as the .then clause isn't attached to a promise. You mentioned that this isn't a problem anymore and that you meant to close this issue. I'm going to close it for now, but if there's another problem then please create a new issue and link to this one for context if needed. Thanks!