I\'m trying to use a Firebase Cloud Function to update a document within my Firestore database, when one of my documents has been updated using a trigger. The trigger is cal
One solution that worked for me:
let serviceAccount = require('../credentials-sb.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://-sandbox.firebaseio.com"
});
firebase use
command for my new project, nor was it added to .firebaserc. I was "using" a project other than the one that the credentials file would have needed (ex: Firebase CLI set to use "project-dev", I had not yet run the firebase use
command for my new "project-sandbox")firebase use project-sandbox
, I ran npm run shell
and executed my function from the emulator and everything worked. The emulator worked as it should for "project-sandbox" as it had for "project-dev".I can only assume this is due to setting a project-id environment variable which is either sensed from the environment when running admin.initializeApp()
or that I could have set manually like this (see comment from @Seb above):
let serviceAccount = require('../credentials-sb.json');
admin.initializeApp({
project-id: '-sandbox'
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://inkling-sandbox.firebaseio.com"
});
I hope this helps! Please let me know if it did.