Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Menyesuaikan alur autentikasi menggunakan fungsi asinkron
Dokumen ini menunjukkan cara memperluas autentikasi Identity Platform menggunakan fungsi Cloud Run asinkron.
Fungsi asinkron memungkinkan Anda memicu tugas non-pemblokiran sebagai respons terhadap pembuatan dan penghapusan pengguna. Fungsi ini berguna untuk memulai operasi yang berjalan lama atau
melakukan tugas tambahan, seperti mengirim email selamat datang.
Untuk mengubah hasil operasi autentikasi secara langsung, lihat Memperluas autentikasi dengan fungsi pemblokiran.
Objek pengguna yang diterima fungsi asinkron tidak berisi
update dari fungsi pemblokiran.
Sebelum memulai
Buat aplikasi dengan Identity Platform. Lihat
Panduan Memulai untuk mempelajari caranya.
Peristiwa onCreate dipicu setiap kali akun pengguna dibuat. Hal ini mencakup sesi dan akun anonim yang dibuat dengan Admin SDK. Fungsi ini tidak dipicu saat pengguna login untuk pertama kali menggunakan token kustom.
Contoh berikut menunjukkan cara mendaftarkan pengendali untuk onCreate:
Peristiwa onCreate dan onDelete menyediakan objek User dan EventContext yang berisi informasi tentang pengguna yang dibuat atau dihapus. Contoh:
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.});
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-11 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)."]]