gpt4 book ai didi

javascript - Firebase,两个项目相同的数据库?

转载 作者:行者123 更新时间:2023-11-30 20:56:31 24 4
gpt4 key购买 nike

让我解释一下情况(请原谅我的英语,我会尽力而为):

我的 Firebase 控制台中有两个 Firebase Web 项目:coretechtest-ce207 和 agon-plugin

coretechtest-ce207是主app,agon-plugin是辅助app,需要连接coretechtest-ce207的auth和database。据我所知,我不能在同一个项目上托管两个应用程序,所以这就是我将项目分开的原因。主要的工作正常,我可以做我想做的一切(注册、数据库等),但我需要主要的和第二个都在同一个身份验证和数据库上。 agon-plugin(第二个)基于 FriendlyChat 应用程序制作,并直接连接到托管该应用程序的服务器。

例如:

// Initializes FriendlyChat.
function FriendlyChat() {
this.initFirebase();

}

// Sets up shortcuts to Firebase features and initiate firebase auth.
FriendlyChat.prototype.initFirebase = async function() {
// Shortcuts to Firebase SDK features.
this.auth = firebase.auth();
this.database = firebase.database();
this.storage = firebase.storage();
// Initiates Firebase auth and listen to auth state changes.
await this.auth.onAuthStateChanged(this.onAuthStateChanged.bind(this));
};

如你所见,没有必要放

apiKey: "AIzaSyAfGm_ILVdfsd--Fw7aascc8tAB73q__Bbko",
authDomain: "coretechtest-ce207.firebaseapp.com",
databaseURL: "https://coretechtest-ce207.firebaseio.com",
projectId: "coretechtest-ce207",
storageBucket: "coretechtest-ce207.appspot.com",
messagingSenderId: "994718782"

我尝试使用这些参数替换它,这样它就可以了

    FriendlyChat.prototype.initFirebase = async function() {
// Shortcuts to Firebase SDK features.

this.auth = 'coretechtest-ce207.firebaseapp.com';
this.database = 'https://coretechtest-ce207.firebaseio.com';
this.storage = 'coretechtest-ce207.appspot.com';

// Initiates Firebase auth and listen to auth state changes.
await this.auth.onAuthStateChanged(this.onAuthStateChanged.bind(this));
};

但是没有运气,你能告诉我我做错了什么吗?我以为替换它会连接到我的主要项目,但它没有...

我希望你能明白我想说的话!

谢谢!

最佳答案

Web 不是 100% 确定,但它应该与 Android 类似:

  • 转到您的控制台面板
  • 在左上角单击“Project OverView”旁边的滚轮
  • 在弹出窗口中点击项目设置
  • 在设置页面向下滚动一点,您应该会看到一个蓝色的“添加应用”(或类似按钮)按钮。

然后将您在第一个应用中所做的所有操作应用到您的第二个应用中

最重要的是,不要在网上发布您的 api key !

关于javascript - Firebase,两个项目相同的数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47603057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com