【问题标题】:Firebase rules when user log out 'Missing or insufficient permissions. Error: Missing or insufficient permissions'用户注销时的 Firebase 规则“缺少权限或权限不足。错误:缺少或不足的权限'
【发布时间】:2019-02-08 19:47:08
【问题描述】:

错误:

'配置文件侦听器出错:缺少权限或权限不足。错误:缺少权限或权限不足。'

我的应用是使用 Reactjs、Redux、Firebase 构建的项目管理器。 您能告诉我为什么在用户注销时出现此错误以及如何解决?

我的规则:

service cloud.firestore {
  match /databases/{database}/documents {
  // Match any {project} document in the 'projects' collection
    match /projects/{project} {
     // Allow signed in users to read write projects
      allow read, write: if request.auth.uid != null; 
    }
    // Match any {user} document in the 'users' collection
    match /users/{user} {
     // Allow users to signup and create an account
      allow create;
      // Allow signed in users to read project details - who create project and when)
      allow read: if request.auth.uid != null;
      // Allow signed in user to update his info only if signed in id == user document id
      allow update, delete: if request.auth.uid == user;
    }
  }
}

【问题讨论】:

  • 您的规则(代码 sn-p 的第 6 行)指定只有经过身份验证的用户才能读取或写入数据
  • 能贴出注销的代码示例吗?客户端是用什么语言编写的?您能否发布错误堆栈跟踪以确保问题是注销而不是其他问题?
  • 我添加了我的应用程序使用 Reactjs、Redux、Firebase 构建。我是新手,所以我无法理解错误堆栈跟踪是什么意思?

标签: firebase google-cloud-firestore logout firebase-security


【解决方案1】:

如果在您注销时发生这种情况,这意味着您仍然有一个 onSnapshot listener 附加到需要对用户进行身份验证的集合。当您注销时,该侦听器将变为无效,因此安全规则会拒绝它。

要删除该消息,请在用户注销之前删除所有此类侦听器。在您的具体情况下,“配置文件侦听器”似乎有问题。

【讨论】:

  • 你能举个例子吗?我看不到在哪里添加了这样的监听器,所以我不知道如何删除它。我正在使用 angular、ts 和 AngularFireAuth,而注销方法只调用 this.angularFireAuth.auth.signOut();
【解决方案2】:

当您注销时,任何现有订阅仍将被订阅,您将收到该错误。您可以在注销前取消订阅或将用户发送到另一个页面并从那里注销。当您将用户发送到另一个页面时,订阅应该被垃圾收集。至少它在角度组件中是这样工作的,不确定反应。

【讨论】:

    猜你喜欢
    • 2021-10-31
    • 1970-01-01
    • 2022-01-15
    • 2021-12-31
    • 2021-08-24
    • 1970-01-01
    • 2022-01-25
    • 2018-04-25
    • 2018-08-30
    相关资源
    最近更新 更多