Firebase Rules to let users see their own data, ER

2019-08-25 02:21发布

I am trying to figure out Firebase Rules that will allow my users to only see their data in their App.

Currently this is my Realtime Database File:

enter image description here

and this is my Firebase Set Rules:

 {
  "rules": {
    "users": {
      "$uid": {
        ".read": "auth.uid === $uid"
      }
    },
    "jobs": {
      "$uid": {
        ".read": "auth.uid === $uid"
      }
    }
  }
}

How do i change the rules to be able to let users see their data that is relevant to their userid?

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-25 02:39

It looks like you're using the user's UID as the key for their data in both jobs and users. In that case, you can ensure that each user can only read their own job and profile with:

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "auth.uid === $uid"
      }
    },
    "jobs": {
      "$uid": {
        ".read": "auth.uid === $uid"
      }
    }
  }
}

Note that this is almost a literal copy of the sample in the Firebase documentation on securing user data.

查看更多
登录 后发表回答