I have two Firebase projects, A and B. When a user follows another user on Project A, data is written to /followers/{followedUid}/{followerUid}
. I would like to perform this same update to Project B.
Users of Project A aren't (can't be) authorized to write to Project B, so I need to use a cloud function. I already do things like this with Node.js functions and firebase-admin using service accounts, but here I want to use a function deployed to Firebase.
How can I add or reference a service account, or otherwise authorize a second project in a Firebase cloud function?
If you've already done this with a local Node.js process and service account, the process within Cloud Functions is going to be pretty similar.
You'll need to initialize the Admin SDK with the credentials (in the form of a JSON file that you deploy with the code) for project B, and then use that for writing the data.
Also see the Firebase documentation on initializing the Admin SDK.