Search code examples
firebasefirebase-securityfirebasesimplelogin

Authenticated user does not have permission to access data stored in Firebase


I have an authenticated user, which is given authentication through using FirebaseSimpleLogin. This user has the token:

'user':{
    email: "[email protected]",
    firebaseAuthToken: SOME TOKEN,
    "id: "4",
    isTemporaryPassword: true,
    md5_hash: "aHash123",
    provider: "password",
    uid: "simplelogin:4"
    }

I have given the authenticated user read permission under the 'rules and security' tab in firebase using:

{
  "rules": {
    "SOME DATA": {
      ".read": "auth.email == '[email protected]'", 
      ".write": true
    }
  }
}

However, when it comes to accessing the data, I get the error:

Error: permission_denied: Client doesn't have permission to access the desired data.

Am I missing something fundamental as to why I do not have read permission?


Solution

  • In the security rules section of firebase, I had made an error.

    {
      "rules": {
        "SOMEDATA": { //NOTE: removal of space character
          ".read": "auth.email == '[email protected]'", 
          ".write": true
        }
      }
    }
    

    Lesson learnt: be very specific with rules, and always follow some convention.