Query-based rules with auth.uid not working

↘锁芯ラ 提交于 2019-12-21 12:31:22

问题


I have the following structure:

events
-LEe7X118dkcH2JhJRe
    description: "Testdescr"
    eventTasks
    participants
        0zlwpSlCazNGjOyMi95h8awshrG2
            lastLogin: 1528641494535
            userKey: "0zlwpSlCazNGjOyMi95h8awshrG2"
            username: "User1"
        6LnYKxRu2SWUrxwIzId8dDpOrl02
            lastLogin: 152856590172
            userKey: "6LnYKxRu2SWUrxwIzId8dDpOrl02"
            username: "User2"

I want to query all events, to which an user participants (like a filter). My Java-Code is:

mDatabaseReference = FirebaseDatabase.getInstance().getReference("event");
mDatabaseReference.orderByChild("participants/"+userId+"/userKey").equalTo(userId).addChildEventListener [...]

This works like a charm - i only receive the correct events.

Now i want to create query-based rules on server side (https://firebase.google.com/docs/database/security/securing-data). So i created a read rule like:

".read": "query.orderByChild == 'participants/'+auth.uid+'/userKey' && query.equalTo == auth.uid"

Problem: i am not able to save that rule. Firebase gives me the error: "Invalid == expression: right operand must be an ordering or string literal when comparing against an ordering.". Why is it not possible to use "query.orderByChild" in combination with auth.uid?

What am i doing wrong?

EDIT: Here are my complete rules:

{
  "rules": {         
    ".write": true,
     "event":{
       ".read": "query.orderByChild == 'participants/'+auth.uid+'/userKey' && query.equalTo == auth.uid"      
     }
  }
}

来源:https://stackoverflow.com/questions/50787713/query-based-rules-with-auth-uid-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!