首页 > 解决方案 > 一个 Web 应用程序的多个项目配置

问题描述

我正在开发一个网络应用程序。我将我的网站部署到一个项目,并希望从另一个项目中获取 firestore 数据。所以我在 html 文件中添加了两个项目配置。为了从第二个 firebase 项目中调用数据,我声明了一个如下所示的变量。

var config = {
     apiKey: "<API_KEY>",
     authDomain: "<PROJECT_ID>.firebaseapp.com",
     databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
     storageBucket: "<BUCKET>.appspot.com",
  };

  var secondaryAppConfig = {
      apiKey: "<API_KEY>",
      authDomain: "<PROJECT_ID>.firebaseapp.com",
      databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
      storageBucket: "<BUCKET>.appspot.com",
    };

  var secondary = firebase.initializeApp(secondaryAppConfig, "secondary");

  var secondaryFirestore = secondary.firestore();

  secondaryFirestore.collection('sample').get().then(snap => {
      var size = snap.size;
      console.log("TotalSample",size);
      // will return the collection size
      document.getElementById('totalStores').textContent = size;
  });

当我像上面那样编写查询以从 secondaryFirestore 获取数据时,我收到如下错误

error.js:149 Uncaught (in promise) Error: Missing or insufficient permissions.
    at new e (error.js:149)
    at t.fromRpcStatus (serializer.js:93)
    at t.fromWatchChange (serializer.js:573)
    at e.onMessage (persistent_stream.js:391)
    at persistent_stream.js:333
    at persistent_stream.js:308
    at async_queue.js:83

Project-A 数据库规则就像只有经过身份验证的人才能访问数据。我无法更改该规则,因为它是机密的。实际上,在这两个数据库项目中,我都使用相同的电子邮件 ID 进行签名。我在这一点上构造。我试了很多都想不通。请让我知道有关如何从 secondaryFirestore 数据库访问数据的任何想法。

提前致谢。

标签: javascripthtmlwebfirebase-authenticationgoogle-cloud-firestore

解决方案


推荐阅读