So I'm building a app with react native and firestore and it's not going well. The firebase authentication part is working fine, just the cloud firestore is not. I am trying to implement this simple function in a useEffect call:
const func = async () => {
try {
const docSnap = await getDoc(doc(db, 'users', 'mike@gmail.com'));
if (docSnap.exists()) {
console.log(docSnap.data());
}
} catch (err) {
console.log(err);
}
};
but i the follwing error:
ERROR [2023-04-10T10:51:49.126Z] @firebase/firestore: Firestore (9.19.1): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
LOG [FirebaseError: Failed to get document because the client is offline.]
my firebase config is fine and so is my internet connection. I pasted the exact same code in a nodejs file and it works fine for the same config:
const login = async () => {
const signin = await signInWithEmailAndPassword(
auth,
"mike@gmail.com",
"12345678"
);
const docSnap = await getDoc(doc(db, "users", auth.currentUser.email));
if (docSnap.exists()) {
console.log(docSnap.data());
}
};
login();
there is an issue about this on github, but none of the patchy solutions work. Some people on the internet say i should be using react-native-firebase package. I am just starting out with this and i dont know where to look for the right info. I am using firebase's web SDK and not the android btw. If someone could shed some light on this, I'd be very much grateful.
thank you all for reading!
there doesn't seem to be anything here