Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Personnaliser le flux d'authentification à l'aide de fonctions asynchrones
Ce document explique comment étendre l'authentification Identity Platform à l'aide de fonctions Cloud Run asynchrones.
Les fonctions asynchrones vous permettent de déclencher des tâches non bloquantes en réponse à la création et à la suppression d'utilisateurs. Elles sont utiles pour lancer des opérations de longue durée ou pour effectuer des tâches auxiliaires, comme l'envoi d'un e-mail de bienvenue.
Pour modifier directement le résultat d'une opération d'authentification, consultez la section Étendre l'authentification avec des fonctions de blocage.
L'objet utilisateur qu'une fonction asynchrone reçoit ne contient pas de mises à jour de la fonction bloquante.
Avant de commencer
Créer une application avec Identity Platform Pour savoir comment, consultez le guide de démarrage rapide.
L'événement onCreate se déclenche chaque fois qu'un compte utilisateur est créé. Cela inclut les sessions et les comptes anonymes créés avec le SDK Admin. La fonction ne se déclenche pas lorsqu'un utilisateur se connecte pour la première fois à l'aide d'un jeton personnalisé.
L'exemple suivant montre comment enregistrer un gestionnaire pour onCreate :
L'événement onDelete se déclenche chaque fois qu'un compte utilisateur est supprimé. L'exemple suivant montre comment enregistrer un gestionnaire pour onDelete :
Les événements onCreate et onDelete fournissent des objets User et EventContext contenant des informations sur l'utilisateur créé ou supprimé. Exemple :
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.});
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (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)."]]