简体   繁体   English

在生产环境中,我应该将 Firebase 管理员的“serviceAccountCredentials.json”放在哪里?

[英]Where should I put "serviceAccountCredentials.json" for Firebase Admin, at production?

in development, I make a config directory and I put the json file in this directory.在开发中,我创建了一个配置目录,并将 json 文件放在该目录中。

>> .env
FIREBASE_ADMINSDK_PATH=./config/firebase-adminsdk-2222222.json

>> test.ts
import { initializeApp, getApps, cert } from 'firebase-admin/app'
const apps = getApps()
if (!apps.length) {
    initializeApp({
        credential: cert(config.FIREBASE_ADMINSDK_PATH)),
    })
}
...

But in production environment, there is only 2 directory in '.output' directory (.output/public, .output/server) So nuxt can not find "./config/firebase-adminsdk-2222222.json" file.但是在生产环境中,'.output'目录中只有2个目录(.output/public,.output/server)所以nuxt找不到“./config/firebase-adminsdk-2222222.json”文件。

Where should I put "serviceAccountCredentials.json" for Firebase Admin, at production?在生产环境中,我应该将 Firebase 管理员的“serviceAccountCredentials.json”放在哪里?

Rather than providing the file location of the service account, you can provide the service account in line as done in this example .无需提供服务帐户的文件位置,您可以像本例中那样在线提供服务帐户。 Reading the service-account.json file should give you enough details to fill in the initialization.阅读service-account.json文件应该会为您提供足够的详细信息来填写初始化。 Copying the initialization here as well:也在这里复制初始化:

// Providing a service account object inline
admin.initializeApp({
  credential: admin.credential.cert({
    projectId: "<PROJECT_ID>",
    clientEmail: "foo@<PROJECT_ID>.iam.gserviceaccount.com",
    privateKey: "-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"
  }),
  databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
});

NOTE: It is advisable to use attached service accounts when possible and encouraged to use the application default credential in most cases.注意:建议尽可能使用附加服务帐户,并鼓励在大多数情况下使用应用程序默认凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该在哪里放置 firebase-auth 用户登录和注册代码? - Where should I put firebase-auth user signin and signup code? 我应该在 blazor maui 应用程序中放置 aws 访问密钥 - where I should put aws access key in blazor maui application 我是否需要手动将大量文件模式放入 firebase.json/hosting/ignore? - Am I expected to manually put lots of file patterns into firebase.json/hosting/ignore? 将 firebase 添加到 React Native 应用程序时,将这些代码放在哪里? - Where to put these codes when adding firebase to the react native app? 我应该如何动态更新 firebase 文档 - how should i dynamically update a firebase document 为什么在Firebase中使用UID? 我应该使用它吗 - Why use UID in Firebase? Should I use it 在 firebase_admin 上使用“where”查询时无法过滤数据 - cannot filter data when using `where` query on firebase_admin 我在哪里可以找到 firebase 验证码? - Where can i finde firebase authentication code? iOS:Firebase:数据库位于不同的区域。 在哪里放链接? - iOS: Firebase: Database lives in a different region. Where to put the link? 如何使用 firebase admin sdk 列出所有用户 - How can I list all users using firebase admin sdk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM