推送ID下的Firebase安全UId

时间:2017-12-30 17:17:00

标签: javascript security firebase

我对firebase安全性比较陌生。我已经阅读了所有文档,我知道这应该是基本的,但是 -

我将数据库结构简化为:

myapp  
    notifications-settings  
        -thL45hSfjdg123432uX  
            newcontact: true  
            uid: 'unique user id'  
        -L-avI3miwgyhIM35Dor  
            newcontact: true  
            uid: 'unique user id' 

“uid”是使用FB或Google登录时生成的经过身份验证的用户ID。我正在尝试使用此规则:

"rules": {  
    "notifications-settings": {  
        "$refID": {  
            ".read": "data.child('uid').val() === auth.uid",  
            ".write": "data.child('uid').val() === auth.uid"  
         }  
    }  
}

我想限制匹配uid的经过身份验证的用户只能读取和更新他们的newcontact值。它的工作原理是只有经过身份验证的用户才能访问其newcontact值,但是没有人可以访问通知设置,这意味着没有人可以实际读取或更新该设置。我的代码中的这一行收到错误:

var prefRef = this.afd.app.database().ref('/notifications-settings')

也许我的问题是尝试访问代码中的通知设置,但我在我的代码中使用它来获取这样的节点:

prefRef.orderByChild('uid')
    .equalTo(this.userInfoProvider.getUserId()).once('value')
    .then
    (function(snapshot) {
        snapshot.forEach(function (childSnap) {

            childSnap.forEach(function (c)
            {

错误:

  

未捕获(承诺):错误:permission_denied at / notifications-settings:客户端无权访问所需数据。错误:permission_denied at / notifications-settings:客户端无权访问所需数据

0 个答案:

没有答案
相关问题