I have a React application and I use firebase
for authentication, database and storage. I had to update the firebase
version, because from my old version, we can’t logging using the Google
option anymore.
I updated to the current last firebase version: ^10.12.2
and I solved the authentication part, but it brokes other parts of the code.
I think that the code works well, but for some reason when I try to get
or set
a document to my local firebase, I can’t and it doesn’t show any log in the firebaseEmulator
.
I can see the new user on the emulator, but not any log. I just can see warnings
in the browser console:
@firebase/firestore: Firestore (10.12.2): WebChannelConnection RPC 'Write' stream 0x4e810535 transport errored: > Object { type: "c", target: {…}, g: {…}, defaultPrevented: false, status: 1 }
This is my configuration:
// clientApp.js
import { initializeApp } from 'firebase/app';
import { getAuth, connectAuthEmulator } from 'firebase/auth';
import { getFirestore, connectFirestoreEmulator } from 'firebase/firestore';
import { getStorage, connectStorageEmulator } from 'firebase/storage';
const firebaseConfig = {
apiKey: ...,
authDomain: ...,
projectId: ...,
storageBucket: ...,
messagingSenderId: ...,
appId: ...,
measurementId: ...,
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const firestore = getFirestore(app);
export const storage = getStorage(app);
if (process.env.NODE_ENV === 'development') {
connectAuthEmulator(auth, 'http://localhost:9099');
connectFirestoreEmulator(firestore, 'localhost', 8080);
connectStorageEmulator(storage, 'localhost', 9199);
}
And I use it like this:
import { firestore } from "../firebase/clientApp";
import { collection, query, where, getDocs } from 'firebase/firestore';
const userCollection = collection(firestore, 'users');
const userQuery = query(userCollection, where('email', '==', user.email));
const userData = await getDocs(userQuery);
console.log('user', userData.docs);
I don’t know where is trying to retreive the data but I don’t get any error and it retreives and empty array.
Like I said I don’t know where is firebase pointing, but is not my emulator, maybe is pointing to the cloud or somewhere else.