David RojoRed
David RojoRed

Reputation: 13

read denied from Firebase for authenticated user

Hi everyone I´m new into this and I´ve been having a problem on simulating security rules. It appears that even with an authenticated uid I cannot access to read "Flashcards" (Line 4: read denied) ; neither with an admin uid, write on "Flashcards" (Line 5). Any idea of what might be happening?

Thanks!

These are my rules:

{
   "rules": {
     "Flashcards": {
        ".read": "root.child('users').hasChild('auth.uid')",
        ".write": "root.child('admins').hasChild('auth.uid')"
         },
     "users": {
      "$uid": {
          ".read": "$uid === auth.uid",
          ".write": "$uid === auth.uid"
              } 
      }
}
}

And this is an example of my database:

{
  "Flashcards": {
    "Deck A": {
      "1": [
        {
            "Question": "Question A",
            "Answer": "Answer A"
        },
        {
            "Question": "Question B",
            "Answer": "Answer B"
        },
        {
            "Question": "Question C",
            "Answer": "Answer C"
        }
        ],
        "2": [
            {
                "Question": "Question A",
                "Answer": "Answer A"
            },
            {
                "Question": "Question B",
                "Answer": "Answer B"
            },
            {
                "Question": "Question C",
                "Answer": "Answer C"
            }
            ]
    }
    },
  "admins": {
    "uid": {
        "name" : "John"
        }
  },
  "users": {
    "uid" : {
        "Actividad" : "Otro"
      },
      "uid" : {
        "Actividad" : "Otro"
      }
    }
}

Upvotes: 1

Views: 115

Answers (1)

Revolution88
Revolution88

Reputation: 698

It is happening that you are using 'auth.uid' as a string, and not as predefined variable. So read rule should be like this (without single quotes):

    ".read": "root.child('users').hasChild(auth.uid)"

Upvotes: 2

Related Questions