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

前端 未结 2 1597
無奈伤痛
無奈伤痛 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:11

    This is depends on the situation of your project on how it works, If you want all authenticated users can read all users data, but cannot write to other users Database, this must be the rule. Current user can only write to his own Database

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

    Rule below is for: Read and write to your own Database (No one can read and write except the currentUser)

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

提交回复
热议问题