Home > OS >  Where should I put "serviceAccountCredentials.json" for Firebase Admin, at production?
Where should I put "serviceAccountCredentials.json" for Firebase Admin, at production?

Time:11-18

in development, I make a config directory and I put the json file in this directory.

>> .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.

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

CodePudding user response:

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. 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.

  • Related