即使使用公共数据库也缺少权限或权限不足

时间:2019-10-28 03:52:05

标签: javascript firebase webpack google-cloud-firestore gatsby

我的Gatsby / firebase项目运行良好,并且停留了一个星期而没有进行任何更改。现在,我只是回来更新一些东西,并且遇到以下错误:

index.js:2177 FirebaseError: Missing or insufficient permissions.
    at new FirestoreError (http://localhost:8000/commons.js:4331:28)
    at JsonProtoSerializer../node_modules/@firebase/firestore/dist/index.esm.js.JsonProtoSerializer.fromRpcStatus (http://localhost:8000/commons.js:19005:16)
    at JsonProtoSerializer../node_modules/@firebase/firestore/dist/index.esm.js.JsonProtoSerializer.fromWatchChange (http://localhost:8000/commons.js:19502:44)
    at PersistentListenStream../node_modules/@firebase/firestore/dist/index.esm.js.PersistentListenStream.onMessage (http://localhost:8000/commons.js:15457:43)
    at http://localhost:8000/commons.js:15386:30
    at http://localhost:8000/commons.js:15426:28
    at http://localhost:8000/commons.js:5669:20

我以为我的firebase规则可能存在一些错误,然后将其更改为公开:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

我仍然遇到相同的错误。我尝试过:

-更新npm依赖项

-清除应用程序存储空间

-gatsby clean

,这些都不起作用。 Firebase身份验证工作正常。您猜出问题可能在哪里吗?

编辑: 我正在使用sagas读取代码:

firebase.js

...
export const authRef = function() {
  return firebase.auth();
}

export const firestoreRef = function() {
  return firebase.firestore();
}
...
import {firestoreRef, authRef} from './firebase';

function* loadProjectsData() {
  try {

    const firestore = firestoreRef();

    const userId = authRef().currentUser.uid;
    const query =
      firestoreRef()
        .collection('projects')

    const snap = yield call(
      [
        query,
        query.get
      ]
    );
  } catch(error)  {
    console.error(error);
  }
}

1 个答案:

答案 0 :(得分:0)

我发现了问题。我团队的一名成员最终从Google云端更改了IAM配置,从而禁用了在Firestore中应用Firebase规则的服务帐户。

在Firebase支持团队的帮助下,我得以发现它。因此,我只是检查了更改的历史记录,并撤消了那些破坏了对数据库访问权限的更改