I'm a newbie in firebase.
How do I get through this below rule?
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
I've tried to change the rule to below,
{
"rules":
{
".read": true,
".write": true,
}
}
but there's an error of
mismatched input '{' expecting {'function', 'service', 'syntax'}
Below is the db structure.
Currently, this is my code (which keeps returning Permission-denied):
// [START initialize_database_ref]
mDatabase = FirebaseDatabase.getInstance().reference
// [END initialize_database_ref]
val result = HashMap<String, Any> ()
result.put("timestamp", getCurrentTime())
result.put("user_id", USER_ID)
result.put("x_position", -1)
result.put("y_position", -1)
mDatabase!!.ref.child("raw data").child("Z9QD79lDzP7MpD6feWeJ").setValue(result).addOnFailureListener(object : OnFailureListener {
override fun onFailure(@NonNull e: Exception) {
Log.d("firebase", e.localizedMessage)
}
})
Any help would be appreciated! Thanks :)
Firebase Security Rules work by matching a pattern against database paths, and then applying custom conditions to allow access to data at those paths. All Rules across Firebase products have a path-matching component and a conditional statement allowing read or write access.
I was able to solve the problem by switching from Cloud Firestore to Realtime Database, and then changing the rule. (After I've changed this, there was no more error showing!)
For others struggling with this problem, the proper solution is to change the false
in
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
To true
while testing. Don't forget to add additional security when going live with your project!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With