Home > Software design >  How to exclude ServiceAccountKey.json when I deploy cloud functions?
How to exclude ServiceAccountKey.json when I deploy cloud functions?

Time:11-14

I downloaded ServiceAccountKey.json to make local cloud functions env. I think ServiceAccountKey.json should not be public and it should not be in GCP. So when I deploy cloud functions, how do I exclude it? Or is that no problem to upload ServiceAccountKey.json using firebase deploy --only functions? Please teach me how to do. Thank you.

CodePudding user response:

I would move the ServiceAccountKey.json file out of the deployment folder. This way, it will never be deployed and you also don't have to add it to the git ignore file. You could also add it to the ignored files in your firebase.json file like so:

{
    "functions": {
    "source": "functions",
    "ignore": [
        "ServiceAccountKey.json"
    ]
  }
}

CodePudding user response:

If you use Firebase Function emulator, you wouldn't need to manage service account locally yourself by using Application Default Credentials. You can initialize Admin SDK like this:

import { initializeApp } from "firebase-admin/app"

const admin = initializeApp(); // <-- no params
  • Related