Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 用户ID写文章的规则_Firebase_Firebase Realtime Database_Firebase Security - Fatal编程技术网

Firebase 用户ID写文章的规则

Firebase 用户ID写文章的规则,firebase,firebase-realtime-database,firebase-security,Firebase,Firebase Realtime Database,Firebase Security,我有一个firebase json,如下所示: 职位: -Hhnfdb743HvGdF (the post key) | --- user: josh | --- profile: /img/img.jpg | --- userid: v5s8fd8f7 (the auth user id from firebase auth) 我只允许此用户ID写入其数据,因此我尝试: "posts": { "$uid": { ".read": true,

我有一个firebase json,如下所示:

职位:

-Hhnfdb743HvGdF (the post key)
 |
 --- user: josh
 |
 --- profile: /img/img.jpg
 |
 --- userid: v5s8fd8f7 (the auth user id from firebase auth)
我只允许此用户ID写入其数据,因此我尝试:

 "posts": {
    "$uid": {
        ".read": true,
        ".write": "auth != null && 
               auth.uid == data.child('userid').val()"
    }
 }
问题是它总是拒绝,即使userid与auth相同。你知道为什么吗

/posts/-Hhnfdb743HvGdF/userid/v5s8fd8f7

谢谢

您正在使用
数据
查找UID,该UID是此操作之前存在的数据。要获取此操作后存在的数据(如果允许此操作),请使用
newData

auth.uid == newData.child('userid').val()"

请参阅上的Firebase文档。

您正在使用
数据
查找UID,UID是此操作之前存在的数据。要获取此操作后存在的数据(如果允许此操作),请使用
newData

auth.uid == newData.child('userid').val()"

请参阅上的Firebase文档。

谢谢您的回答!我将数据更改为新数据,但仍然拒绝。。。还有什么想法吗/您可以编辑您的问题以包含以下内容吗?请确保尽可能多地硬编码,并记录无法硬编码的值,例如活动用户的UID。感谢您的回答!我将数据更改为新数据,但仍然拒绝。。。还有什么想法吗/您可以编辑您的问题以包含以下内容吗?确保尽可能多地硬编码,并记录无法硬编码的值,例如活动用户的UID。