Firebase 规则获取目标用户 uid

Firebase rule get target user uid

我正在编写一个 Firebase 规则以允许用户 a 访问用户 b 的 'Test' 属性:

"Test": {
    ".read":"root.child('Users').child(auth.uid).child('Test').child('subtest').val().contains('xxxxxxxxxxxxxxxxMdv3wQRjIs2')",
}

刚发现规则检查的是请求者(用户 a)而不是目标用户 b(可能是错误的 :))。

有没有办法写一个规则来代表目标用户的uid,比如请求者的'auth.uid'?

或者在目标用户级别可以做些什么?

这应该为您提供用户的 UID:

let userID = FIRAuth.auth()!.currentUser!.uid

这是您想要做的吗?

"$target":{
        ".write": "root.child('path').val() == 'Value'"
      }

"Users": { //Path to where you store your users (case sensitive)
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }

编辑:OP 使用 ".read": "data.child('allowed').val() == auth.uid",

找到了解决方案