Search code examples
firebaseenvironment-variablesnuxt3.jsfirebase-toolsvuefire

How to point GOOGLE_ACCOUNT_CREDENTIALS environment variable in a VueFire project?


I was trying to run a VueFire project. The docs mentioned that I should use a service account. So I downloaded one and put it in my project folder, added it to .gitignore and point an environment variable to it:

# My .env file
GOOGLE_ACCOUNT_CREDENTIALS=service-account.json

I tried running it using Firebase emulator, and I got the following warning:

Failed to parse service account json file: Error: Service account object must contain a string "project_id" property.

When I checked my terminal, I see the following warning popping up when emulator is starting up:

functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /home/starleaf1/.config/firebase/starleaf1_gmail_com_application_default_credentials.json. Non-emulated services will access production using these credentials. Be careful!

It looks like the emulator ignores the .env and looks for the service account file somewhere else. Is there a way to resolve this?

I have also tried:

  • Setting the env value to absolute path, i.e: /home/starleaf1/service-account.json, but it still doesn't work.
  • Naming the file .env.local or .env.development

Solution

  • As it turns out, I already have a GOOGLE_CLOUD_CREDENTIALS in my environment variables. A .env file will not override already-existing variables. To point it to the correct file, execute this before starting Firebase Emulator Suite:

    export GOOGLE_ACCOUNT_CREDENTIALS=service-account.json
    

    When building for production, Nuxt will take into the .env build.