Background Trigger Functions

Learn to write background trigger functions in Firebase.

In the Introduction to Cloud Functions lesson, we mentioned that we can trigger Cloud Functions in response to events coming from Firebase products. These types of functions are called background trigger functions. Examples of such event triggers include the following:

  • When a user signs up with Firebase authentication
  • A write, update, or delete operation on the Realtime Database or Cloud Firestore
  • A conversion event in Google Analytics

With the Cloud Functions for Firebase SDK, we can monitor these events and trigger a function in response to such events. This allows us to handle them the way we want to. Let’s take a look at some of these.

Note: All background trigger functions must be terminated by returning a promise that is fulfilled after the function completes all the work to be done. However, if there is no work, we can return null to terminate the function.

Authentication triggers

We can trigger Cloud Functions for Firebase in response to a user creation or a deletion event on our Firebase application. We do this by using either the onCreate or onDelete handlers with the functions.auth.user() function. These handlers take a callback function with a parameter, user. We use this parameter to access the user’s attributes, similar to the client SDK:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy