【问题标题】:realtime firebase database read data from request实时firebase数据库从请求中读取数据
【发布时间】:2021-10-18 07:31:25
【问题描述】:

所以我有 3 个集合

1-案例

3- 所有者(内箱收集)

2- 邀请

在正常情况下,当用户添加邀请时,我检查该托盘此操作的用户是否为所有者,从 newDate 获取 caseId 并从 auth.uid 获取 uid,并通过存在于 cases collection 中比较这些数据

但它总是给我权限被拒绝。

 // Any one have cases
 "cases":{ 
   ".write" : "auth.uid != null"

  // Store id of owner only when case created first time
   "owner"  : {
     ".write": "!data.exists()"
   }
 }

//only Owner of case can add invitations
 "invitations":{
   ".write" :"root.child('cases').child(newData.child('caseId').val()).child('owner').child(auth.uid).exists()",
 },  

我发送到invitations 集合的数据是

Invitation(
  endAt: DateTime.now().add(Duration(days: 1)),
  id: invitationId,
  caseId: caseId,
);

编辑 当我尝试将 newData.child('caseId').val() 替换为 caseId 值作为静态字符串值时,它正在工作!!

【问题讨论】:

  • 安全规则不做任何事情。只有对它们运行代码后,它们才会变得活跃。请编辑您的问题以显示minimal code that reproduces the problem you have with these rules、您希望该代码做什么以及会发生什么。
  • @FrankvanPuffelen 我已经更新了我的问题,希望这次我已经解释清楚了
  • @FrankvanPuffelen。我错了,因为我在父母而不是孩子中使用了newDate,所以我将我的规则放在"$invitationId"下并且它的工作,所以我对此是否正确,我只能在孩子内部使用newDate创建不在他的父母?
  • 很高兴听到您发现问题 Mahmoud! ??????

标签: firebase-realtime-database firebase-security


【解决方案1】:

对于谁遇到这个问题,我错了,因为我在父母而不是孩子中使用了newDate,所以我将我的规则放在"$invitationId" 下并且它的工作。

 //only Owner of case can add invitations
     "invitations":{
       "$invitationId":{
        ".write" :"root.child('cases').child(newData.child('caseId').val()).child('owner').child(auth.uid).exists()",
       }
     },

  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2022-10-07
    • 2023-02-23
    • 2021-04-10
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多