index.esm2017.js:370 Uncaught (in promise) FirebaseError: Missing or insufficient permissions in ReactJs

index.esm2017.js:370 Uncaught (in promise) FirebaseError: Missing or insufficient permissions in ReactJs

完全错误

Uncaught (in promise) FirebaseError: Missing or insufficient permissions.
    at index.esm2017.js:10913
    at Y.<anonymous> (index.esm2017.js:10865)
    at qb (eventtarget.js:351)
    at D (eventtarget.js:481)
    at Z.wa (webchannelbasetransport.js:369)
    at sc (webchannelbase.js:2193)
    at tc (channelrequest.js:941)
    at M.k.Ia (channelrequest.js:619)
    at M.k.gb (channelrequest.js:596)
    at qb (eventtarget.js:351)

Get https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel?database=projects%2Fnetflixclone-001%2Fdatabases%2F(default)&gsessionid=Il1qOZrt3xwI9HsitxL5j4_GdibS-ga9&VER=8&RID=rpc&SID=MgLGFVuM420X7FPF_SYqrg&CI=0&AID=0&TYPE=xmlhttp&zx=fhlml28c0sd1&t=1 net::ERR_FAILED 200

规则(云火石)

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

seedData代码(data.js)

export function seedDatabase(firebase) {
    function getUUID() {
      // eslint gets funny about bitwise
    //    eslint-disable 
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
          const piece = (Math.random() * 16) | 0;
          const elem = c === 'x' ? piece : (piece & 0x3) | 0x8;
          return elem.toString(16);
      });
      /* eslint-enable */
    }
  
    /* Series
      ============================================ */
    // Documentaries
    firebase.firestore().collection('series').add({
      id: getUUID(),
      title: 'Tiger King',
      description: 'An exploration of big cat breeding and its bizarre underworld, populated by eccentric characters.',
      genre: 'documentaries',
      maturity: '18',
      slug: 'tiger-king',
    });
    firebase.firestore().collection('series').add({
      id: getUUID(),
      title: 'Amanda Knox',
      description: 'Amanda Marie Knox is an American woman who spent almost four years in an Italian prison.',
      genre: 'documentaries',
      maturity: '12',
      slug: 'amanda-knox',
    });

firebase.prod.js class

import Firebase from 'firebase/compat/app'
import 'firebase/compat/auth';
import 'firebase/compat/firestore';

// 1) when seeding the database you'll have to uncomment this!
import { seedDatabase } from '../data';

const firebaseConfig = {
    ...
  };

  const firebase = Firebase.initializeApp(firebaseConfig);

// 2) when seeding the database you'll have to uncomment this!
seedDatabase(firebase);
// 3) once you have populated the database (only run once!), re-comment this so you don't get duplicate data

export { firebase };

所有其他页面工作正常

您的安全规则不允许任何人读取或写入您的数据库。如果您将规则设置为 true,如下所示,它应该允许您编写:

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

现在的问题是互联网上的任何人都可以阅读或写入您的系列文章 collection。我很难为此编写规则,因为没有详细说明谁可以 read/write 这个 collection。我建议阅读有关 Firestore Security Rules 的内容,以仅允许授权用户访问。