Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Personalizzazione del flusso di autenticazione mediante funzioni asincrone
Questo documento mostra come estendere l'autenticazione di Identity Platform utilizzando le funzioni Cloud Run asincrone.
Le funzioni asincrone ti consentono di attivare attività non bloccanti in risposta alla creazione e all'eliminazione degli utenti. Sono utili per avviare operazioni a lunga esecuzione o per eseguire attività ausiliarie, come l'invio di un'email di benvenuto.
Per modificare direttamente il risultato di un'operazione di autenticazione, consulta
Estensione dell'autenticazione con le funzioni di blocco.
L'oggetto utente ricevuto da una funzione asincrona non contiene aggiornamenti della funzione di blocco.
Prima di iniziare
Crea un'app con Identity Platform. Per scoprire come, consulta la guida rapida.
L'evento onCreate viene attivato ogni volta che viene creato un account utente. Sono inclusi
gli account e le sessioni anonimi creati con l'SDK Admin. La funzione non si attiva quando un utente accede per la prima volta utilizzando un token personalizzato.
L'esempio seguente mostra come registrare un gestore per onCreate:
Gli eventi onCreate e onDelete forniscono oggetti User e EventContext
che contengono informazioni sull'utente creato o eliminato. Ad esempio:
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.});
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)."]]