【问题标题】:Firebase rules with Bolt not allowing write of new blog post带有 Bolt 的 Firebase 规则不允许撰写新的博客文章
【发布时间】:2016-02-23 10:30:05
【问题描述】:

我希望使用 Firebase 创建一个博客。

我的规则是:

type Post {
    title: String,
    timestamp: Number,
    content: String
}

path / {
    write() {false}
    read() {true}

    /posts/{post} is Post {
        write() {isAdmin()}
    }
}

isAdmin() {auth != null && auth.uid == 'xxx-xxx-xxx-xxx-xxx'}

阅读帖子有效。但是当我想发布一个时,它会抛出一个permission_denied

我通过authWithPassword方法成功登录并提交帖子。

firebase.authWithPassword({email: 'myEmail@email.com', password: 'myPass'}).then(function(authData) {
  if (authData) {
    firebase.child('/articles').push().set(json);
  }
});

json 等于

{
  'title': 'My title',
  'timestamp': 89430867,
  'content': 'My Content'
}

我该如何解决这个错误?

【问题讨论】:

  • 您可以将json 的值添加到问题中吗?了解您如何进行身份验证然后编写可能也很有用。
  • 感谢您添加 JSON,这似乎符合 Bolt 规范。您还可以显示从身份验证到set() 的流程吗?我怀疑错误可能在那里。

标签: firebase firebase-security firebase-authentication


【解决方案1】:

最后,

我尝试通过 Firebase 提供的模拟器提交帖子。有效。所以,规则很好。

我决定比较一下我网站的 websockets 框架和模拟器的框架。

我发现我在代码中犯了一个错误。我试图发送一个字符串而不是一个对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2014-02-19
    • 2018-01-05
    • 2018-02-23
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    相关资源
    最近更新 更多