Closed KishiTheMechanic closed 1 year ago
What rules are configured for Firestore in the emulator? You can see this through the emulator UI.
I appreciate your support.
I'm putting firestore.rules
on the project rules.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /User/{userId}/{document=**} {
allow read: if request.auth != null;
allow write: if request.auth.uid == userId;
}
}
}
I couldn't find the rules on the emulator. Can I set the rule file path or something in somewhere like firebase.json?
The error looks like exactly when the rule is not affected...
I found new error logs for this on the log from React Native, so sharing them.
ERROR [2023-08-08T14:51:40.430Z] @firebase/firestore: Firestore (9.17.2): 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.
WARN Possible Unhandled Promise Rejection (id: 0):
FirebaseError: Failed to get document because the client is offline.
FirebaseError: [code=unavailable]: Failed to get document because the client is offline.
WARN Possible Unhandled Promise Rejection (id: 1):
FirebaseError: Failed to get document because the client is offline.
FirebaseError: [code=unavailable]: Failed to get document because the client is offline.
WARN Possible Unhandled Promise Rejection (id: 2):
FirebaseError: Failed to get document because the client is offline.
FirebaseError: [code=unavailable]: Failed to get document because the client is offline.
Thank you always. Have a great day☀
My firebase.json is this:
{
"functions": [
{
"source": "functions/openai",
"codebase": "openai",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
],
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"storage": {
"rules": "storage.rules"
},
"emulators": {
"auth": {
"port": 9099
},
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"pubsub": {
"port": 8085
},
"hosting": {
"port": 8000
},
"storage": {
"port": 9199
},
"ui": {
"enabled": true
},
"singleProjectMode": true
}
}
Thank you so much for Firebase support team, I got some issues similar from this and Firestore problem was solved with:
const firestoreDb = initializeFirestore(firebaseApp, {
experimentalForceLongPolling: true,
})
Instead of using
const firestoreDb = getFirestore(firebaseApp)
initializeFirestore
solved the problem with Android development.
However,
ERROR [TypeError: Network request failed]
ERROR [TypeError: Cannot read property 'status' of undefined]
These errors still exist.
Do we need to use 10.2.2.0
for Firebase Functions as well?
Ohhhhhh it finally works well!!
We need to change the emulator host by the platform.
platform === 'web'
? '127.0.0.1'
: platform === 'android'
? '10.0.2.2'
: '0.0.0.0'
Now it's working on the Android too. It's so nice!!!!🙌
https://github.com/elsoul/skeet-solana-mobile-stack It's now working with the emulators🚀🔥
Thank you for your support always!
Have a great day☀
I'm glad you figured it out and I love the enthusiasm. I'll let the team know that long polling fixed this issue with connecting to the Firestore emulator.
Also, a note to future readers, the last comment is a fix for the issue connecting to the functions emulator.
Yes, thank you for your note.
The way to call Firebase Functions looks like this as a side note.
const callFirebaseFunctions = async () => {
const platformDevIP =
Platform.OS === 'web'
? '127.0.0.1'
: Platform.OS === 'android'
? '10.0.2.2'
: '0.0.0.0'
const url =
process.env.NODE_ENV === 'production'
? `https://${
functionDomain
}/${functionName}/${toKebabCase(methodName)}`
: `http://${platformDevIP}:5001/${projectId}/${region}/${methodName}`
const fbToken = await auth?.currentUser?.getIdToken()
const res = await fetch(`${url}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${fbToken}`,
},
body: JSON.stringify(params),
})
return res
}
Operating System
iOS 16.4, Android 13
Browser Version
Safari/604.1
Firebase SDK Version
9.17.2
Firebase SDK Product:
Firestore
Describe your project's tooling
Describe the problem
I could use the Auth emulator correctly but not the Firestore emulator from React Native (Expo) with iOS and Android emulators on my Mac.
the settings are like this:
I'm getting these errors when I use firestore:
Please tell me how to use the Firestore emulator from mobile emulators (iOS and Android) with React Native(Expo).
Thank you always.
Steps and code to reproduce issue
Please use this repository to reproduce issue.
https://github.com/elsoul/skeet-app
I'm using Expo: https://expo.dev/