gpt4 book ai didi

javascript - 赫罗库 : Firebase can't load credentials

转载 作者:行者123 更新时间:2023-12-02 23:03:49 33 4
gpt4 key购买 nike

问题摘要

我在 Heroku 上托管使用 Firebase 的 Node.js 服务器,当我尝试在 Heroku 上运行时,收到以下错误,指出它无法加载我的凭据。

在我的本地计算机上运行时它运行得很好。我正在使用 firebase-admin npm 包来配置我的 firebase 连接/实例。

有人遇到过这种情况吗?如果是这样,我希望得到您的帮助!

Heroku 错误

错误:无法加载默认凭据。浏览至https://cloud.google.com/docs/authentication/getting-started了解更多信息。

代码

Firebase 管理配置文件

这是我用来配置 Firebase 管理实例的文件

const admin = require('firebase-admin');

admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: "https://esports-competition-2.firebaseio.com"
}); //this also allows me to use Google OAuth2 refresh token

const db = admin.firestore();

module.exports = db;

将数据保存到firebase的函数

const db = require("../../configs/firebaseConfig");

async function firestorePush(userId, eventType, data) {
try {
//read database
//if userId contains eventType singleEntry then remove from database
const timeStamp = new Date();
userId = userId.toString();
const userDoc = db.collection("pushData").doc(userId);
const pushData = await userDoc.set(
{
event: {
eventType,
data,
timeStamp
}
},
{ merge: true }
);
console.log("Document set in FireStore", pushData);
} catch (err) {
console.log("errpr pushing to firebase", err);
}
}

最佳答案

根据documentation on admin.credential.applicationDefault() :

Google Application Default Credentials are available on any Google infrastructure, such as Google App Engine and Google Compute Engine.

由于 Heroku 不是 Google 基础设施,因此您必须使用 documentation on initializing the SDK 中显示的其他选项之一来初始化 Admin SDK。 .

关于javascript - 赫罗库 : Firebase can't load credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57682262/

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