Firebase permission-denied

user3415167 picture user3415167 · Dec 26, 2017 · Viewed 8.3k times · Source

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.

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 :)

Answer

user3415167 picture user3415167 · Dec 26, 2017

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!) enter image description here