Extend Firebase Authentication with Cloud Functions

You can trigger a Cloud Function in response to the creation and deletion of user accounts via Firebase Authentication. For example, you could send a welcome email to a user who has just created an account in your app. Examples in this page are based on a sample that does exactly this — sends welcome and farewell emails on user creation and deletion.

For more examples of use cases, see What can I do with Functions?

Trigger a function on user creation

You can create a Cloud Function that triggers when a Firebase user is created using the functions.auth.user().onCreate() event handler.

Firebase accounts can be created in the following events:

  • A user creates an email and password account
  • A user signs in for the first time using a federated identity Provider
  • A user signs in to a new anonymous auth session for the first time
  • A user signs in for the first time using a custom token
  • The developer creates an account using the Firebase Admin SDK

Access user attributes

Via event.data returned by auth.user(), you can access the list of user attributes available in the UserRecord object. For example, you can get the user's email and display name as shown:

Trigger a function on user deletion

Just as you can trigger a Cloud Function on user creation, you can respond to user deletion events. Use the functions.auth.user().onDelete() event handler as shown:

Send feedback about...

Need help? Visit our support page.