Firebase Rules with auth.uid

0

Reading the firebase documentation I realized that I could modify the rules so that only specific access was available to each user in a particular branch.

{
 "rules": {
  "users": {
   "$uid": {
    ".write": "$uid === auth.uid"
  } 
}

But I can not find the right way to do it, this is my data in firebase.

(assuming that authUid is the Auth.uid that it generates when authenticating with firebase)

these are my rules in that specific place, all the others are public

 "usuarios": {
    "$uid": {
      ".write": "$uid === auth.uid"
    }
  },

How can I make my rule valid using $ uid in my rules, so that only the user enters its corresponding branch and does not enter branches of other users?

    
asked by eddy Hause 12.07.2018 в 23:03
source

1 answer

0

Rule that uses the variable auth to guarantee that each user can only write in a specific path, the same user:

{
  "rules": {
    "users": {
      "$user_id": {
        ".write": "$user_id === auth.uid"
      }
    }
  }
}

If you want to restrict access to this data so that only the user who has logged in can see their own data, their rules would look like this:

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "auth != null && auth.uid == $uid"
      }
    }
  }
}

official documentation can find more information.

    
answered by 13.07.2018 в 02:05