Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To enable access to a database from a different project in Firebase Cloud Functions, follow these instructions:

  1. In the Firebase console, go to the project that hosts the database you want to access.

  2. Go to the “Project Settings” page and click on the “Service Accounts” tab.

  3. Generate a new private key for the Firebase service account associated with your project.

  4. Download and store the private key JSON file securely on your local machine.

  5. In the project where you want to deploy the Cloud Function, open the Cloud Functions config.

  6. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path where you stored the private key JSON file.

  7. Import the Firebase Admin SDK in your code and initialize it with the credentials from the private key JSON file.

  8. Use the SDK to access the database from the other project.

Note: Make sure the service account associated with the project where you want to deploy the Cloud Function has the necessary permissions to access the database in the other project. You may need to adjust the IAM roles and permissions accordingly.