What rules to use on Firebase-RealtimeDatabase to let users register and login?

前端 未结 2 1604
無奈伤痛
無奈伤痛 2021-01-14 07:53

In order to let Android users register and login through my app I have set the .read and .write as true<

2条回答
  •  佛祖请我去吃肉
    2021-01-14 08:20

    Using the following rules:

    {
      "rules": {
          ".read": "auth != null",
          ".write": "auth != null"
      }
    }
    

    You'll give read and write access only to authenticated users. For more information, please see the official documentation regarding Firebase security rules.

    According to your comment, you should then verify if the user that performs an operation is actually the authenticated user. So for example, let's say you want only authenticated users to able to access their accounts, the following rules are required:

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

提交回复
热议问题