Stay organized with collections
Save and categorize content based on your preferences.
Customizing the authentication flow using asynchronous functions
This document shows you how to extend Identity Platform authentication
using asynchronous Cloud Run functions.
Asynchronous functions let you trigger non-blocking tasks in response to user
creation and deletion. They are useful for starting long-running operations or
performing auxiliary tasks, like sending a welcome email.
To directly modify the result of an authentication operation, see
Extending authentication with blocking functions.
The user object that an asynchronous function receives does not contain
updates from the blocking function.
Before you begin
Create an app with Identity Platform. See the
Quickstart to learn how.
The onCreate event triggers whenever a user account is created. This includes
anonymous sessions and accounts created with the Admin SDK. The function does
not trigger when a user signs in for the first time using a custom token.
The following example shows how to register a handler for onCreate:
The onCreate and onDelete events provide User and EventContext objects
that contain information about the created or deleted user. For example:
Node.js
exports.myFunction=functions.auth.user().onCreate((user,context)=>{constemail=user.email;// The email of the user.constdisplayName=user.displayName;// The display name of the user.});
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Customizing the authentication flow using asynchronous functions\n================================================================\n\nThis document shows you how to extend Identity Platform authentication\nusing asynchronous [Cloud Run functions](/functions).\n\nAsynchronous functions let you trigger non-blocking tasks in response to user\ncreation and deletion. They are useful for starting long-running operations or\nperforming auxiliary tasks, like sending a welcome email.\n\nTo directly modify the result of an authentication operation, see\n[Extending authentication with blocking functions](/identity-platform/docs/blocking-functions).\nThe user object that an asynchronous function receives does not contain\nupdates from the blocking function.\n\nBefore you begin\n----------------\n\nCreate an app with Identity Platform. See the\n[Quickstart](/identity-platform/docs/quickstart-email-password) to learn how.\n\nCreating an asynchronous function\n---------------------------------\n\nTo create and deploy an asynchronous function, follow the steps in\n[Get started: write, test, and deploy your first functions](https://firebase.google.com/docs/functions/get-started).\n\nResponding to user creation\n---------------------------\n\nThe `onCreate` event triggers whenever a user account is created. This includes\nanonymous sessions and accounts created with the Admin SDK. The function does\nnot trigger when a user signs in for the first time using a custom token.\n\nThe following example shows how to register a handler for `onCreate`: \n\n### Node.js\n\n exports.myFunction = functions.auth.user().onCreate((user) =\u003e {\n // TODO.\n });\n\nResponding to user deletion\n---------------------------\n\nThe `onDelete` event triggers whenever a user account is deleted. The following\nexample shows how to register a handler for `onDelete`: \n\n### Node.js\n\n exports.myFunction = functions.auth.user().onDelete((user) =\u003e {\n // TODO.\n });\n\nGetting user information\n------------------------\n\nThe `onCreate` and `onDelete` events provide `User` and `EventContext` objects\nthat contain information about the created or deleted user. For example: \n\n### Node.js\n\n exports.myFunction = functions.auth.user().onCreate((user, context) =\u003e {\n const email = user.email; // The email of the user.\n const displayName = user.displayName; // The display name of the user.\n });\n\nSee the\n[`UserRecord` API reference](https://firebase.google.com/docs/reference/admin/node/firebase-admin.auth.userrecord)\nand the\n[`EventContext` API reference](https://firebase.google.com/docs/reference/functions/firebase-functions.eventcontext)\nfor a list of available fields.\n\nWhat's next\n-----------\n\n- Extend authentication with [blocking functions](/identity-platform/docs/blocking-functions).\n- Learn more about [Cloud Run functions](/functions/docs)."]]