Google Compute Engine @firebase/database: FIREBASE WARNING

Viewed 158

We have a Google Compute Engine that is used to execute nodejs scripts, where one of them connects to Firebase Realtime Database. When this script attempts to connect to RTD it fails with the following:

@firebase/database: FIREBASE WARNING: Provided authentication credentials for the app named "[DEFAULT]" are invalid. This usually indicates your app was not initialized correctly. Make sure the "credential" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.

The script connects to an instance that is under the same project. The databaseURL is assigned via the FIREBASE_CONFIG environment variable, and default application credentials are used to authenticate with the various GCP services.

Notes

  • Other services such as Firestore and Firebase Auth work without issue: only Realtime Database is a problem.
  • The databaseURL is correct and is used in an App Engine instance that executes without issue.
  • We have tried passing in the databaseURL as part of the admin.initializeApp() config without success.
1 Answers

I had this problem for the past few weeks and was just able to fix it by adding some scopes with:

gcloud compute instances set-service-account [INSTANCE_NAME] \
  --service-account "your.gserviceaccount.com" \
  --scopes "https://www.googleapis.com/auth/firebase.database,https://www.googleapis.com/auth/userinfo.email"

This is documented in setting scopes for Realtime Database and Authentication, although I also overlooked it there and only found it once someone pointed it out to me.

Related