【发布时间】: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