Skip to content Skip to sidebar Skip to footer

How To Scope Firebase In Nested Promise Cloud Functions

I am trying to set a few variables from Firebase and then pass those into a anotherfunction. Currently, the Promise.all is properly setting foo and bar, but an error is being throw

Solution 1:

You need to include the Firebase Admin SDK, typically called admin.

As shown and explained in the getting started documentation for functions:

Import the required modules and initialize

For this sample, your project must import the Cloud Functions and Admin SDK modules using Node require statements. Add lines like the following to your index.js file:

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

These lines load the firebase-functions and firebase-admin modules, and initialize an admin app instance from which Realtime Database changes can be made.

You then use it like this:

return admin.database().ref().update(updates);

Also see this complete example in the functions-samples repo.

Post a Comment for "How To Scope Firebase In Nested Promise Cloud Functions"