【问题标题】:FIREBASE WARNING: set at /notifications/ failed: permission_deniedFIREBASE 警告:设置在 /notifications/ 失败:permission_denied
【发布时间】:2018-03-02 10:54:40
【问题描述】:

我按照教程 here 的说明进行操作。唯一的区别是我将通知的订阅和发送分为 2 个不同的页面。这里是Subscribe Page,这里是Dashboard

问题是在用户订阅成功后,我尝试在仪表板中推送通知,我收到一个错误

FIREBASE WARNING: set at /notifications/-L6ZAsl77V-patpjL8vT failed: permission_denied

但与tutorial/demo相比,没有错误,消息是通过最终用户推送的。

有什么想法吗?

数据库安全规则:

{
  "rules": {
    "tokens": {
        ".indexOn": ["uid", "token"],
        ".read": "auth != null",
        ".write": "auth != null",
        "$token": {
            ".validate": "newData.hasChildren(['uid', 'token']) && newData.child('uid').val() == auth.uid"
        }
    },
    "notifications": {
        ".read": "auth != null",
        ".write": "auth != null",
        "$notification": {
            ".validate": "newData.hasChildren(['user', 'message', 'userProfileImg'])"
        }
    }
  }
}

【问题讨论】:

  • 听起来您遇到了 Firebase 规则问题。 IIRC,默认情况下所有内容都是禁用的,因此您需要自己设置规则以允许这样做。你能告诉我们你的notifications节点的firebase规则是什么样的吗?
  • { "rules": { "tokens": { ".indexOn": [ "uid", "token" ], ".read": "auth != null", ".write" : "auth != null", "$token": { ".validate": "newData.hasChildren(['uid', 'token']) && newData.child('uid').val() == auth .uid" } }, "notifications": { ".read": "auth != null", ".write": "auth != null", "$notification": { ".validate": "newData.hasChildren (['user', 'message', 'userProfileImg'])" } } } }
  • @CRice,奇怪的是代码是按照教程和她的演示工作就像一个魅力
  • 此错误消息与云消息传递无关,也与您的 Firebase 数据库及其安全规则无关。请编辑您的问题(下面有一个链接)以包含触发错误/警告消息的写入操作。
  • 好的,看起来合法(并且与链接的仓库中的相同),因此规则不是问题。可能是尝试写入的用户未经过身份验证(我觉得可能是这样),或者他们尝试设置的数据没有那些必填字段。你能告诉我们尝试写入的代码吗?

标签: javascript firebase firebase-realtime-database firebase-cloud-messaging firebase-security


【解决方案1】:

这是一个愚蠢的错误。我认为这是演示和我自己的 1:1 之间的关系。

在我假设调用/notifications 的一个JS 文件中,我删除了useruserProfileImg,而没有更新database.rule.json 中的规则。还是这样写的:

 "$notification": {
      ".validate": "newData.hasChildren(['user', 'message', 'userProfileImg'])"
 }

当我从 json 文件中删除 'user''userProfileImg' 时,一切都恢复正常了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-06
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-03
    • 2019-06-03
    相关资源
    最近更新 更多