Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bạn có thể kích hoạt các hàm để phản hồi việc tạo và xoá tài khoản người dùng Firebase. Ví dụ: bạn có thể gửi email chào mừng cho người dùng vừa tạo tài khoản trong ứng dụng của bạn. Các ví dụ trên trang này dựa trên một mẫu thực hiện chính xác việc này – gửi email chào mừng và tạm biệt khi tạo và xoá tài khoản.
Tài khoản Firebase sẽ kích hoạt các sự kiện tạo người dùng cho Cloud Functions khi:
Người dùng tạo tài khoản email và mật khẩu.
Người dùng đăng nhập lần đầu bằng một nhà cung cấp danh tính được liên kết.
Nhà phát triển tạo một tài khoản bằng Admin SDK.
Người dùng đăng nhập vào một phiên xác thực ẩn danh mới lần đầu tiên.
Sự kiện Cloud Functionskhông được kích hoạt khi người dùng đăng nhập lần đầu bằng mã thông báo tuỳ chỉnh.
Truy cập vào thuộc tính người dùng
Từ dữ liệu người dùng được trả về cho hàm của bạn, bạn có thể truy cập vào danh sách các thuộc tính người dùng có trong đối tượng UserRecord của người dùng mới tạo. Ví dụ: bạn có thể lấy email và tên hiển thị của người dùng như minh hoạ:
Giống như có thể kích hoạt một hàm khi người dùng được tạo, bạn có thể phản hồi các sự kiện xoá người dùng. Sử dụng trình xử lý sự kiện functions.auth.user().onDelete() như minh hoạ:
Nếu đã nâng cấp lên Firebase Authentication with Identity Platform, bạn có thể mở rộng Firebase Authentication bằng cách sử dụng chặn Cloud Functions.
Các hàm chặn cho phép bạn thực thi mã tuỳ chỉnh để sửa đổi kết quả của một người dùng đăng ký hoặc đăng nhập vào ứng dụng của bạn. Ví dụ: bạn có thể ngăn người dùng xác thực nếu họ không đáp ứng một số tiêu chí nhất định hoặc cập nhật thông tin của người dùng trước khi trả thông tin đó về ứng dụng khách của bạn.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-09 UTC."],[],[],null,["\u003cbr /\u003e\n\nYou can trigger functions in response to the creation and deletion of\nFirebase user accounts. For example, you could send a welcome email to a\nuser who has just created an account in your app. Examples on this page are\nbased on a sample that does exactly this---sends welcome and farewell emails\nupon account creation and deletion.\n\nFor more examples of use cases, see\n[What can I do with Cloud Functions?](/docs/functions/use-cases).\n| **Note:** Cloud Functions for Firebase (2nd gen) does not provide support for the events and triggers described in this guide. Because 1st gen and 2nd gen functions can coexist side-by-side in the same source file, you can still develop and deploy this functionality together with 2nd gen functions.\n\nTrigger a function on user creation\n\nYou can create a function that triggers when a Firebase user is\ncreated using the\n[`functions.auth.user().onCreate()`](/docs/reference/functions/firebase-functions.auth.userbuilder#authuserbuilderoncreate)\nevent handler:\n\n\u003cbr /\u003e\n\n```gdscript\nexports.sendWelcomeEmail = functions.auth.user().onCreate((user) =\u003e {\n // ...\n});\n```\n\n\u003cbr /\u003e\n\nFirebase accounts will trigger user creation events for\nCloud Functions when:\n\n- A user creates an email account and password.\n- A user signs in for the first time using a federated identity provider.\n- The developer creates an account using the Admin SDK.\n- A user signs in to a new anonymous auth session for the first time.\n\nA Cloud Functions event is *not* triggered when a user signs in for the\nfirst time using a custom token.\n\nAccess user attributes\n\nFrom the user data returned to your function, you can\naccess the list of user attributes available in the newly created user's\n[`UserRecord`](/docs/reference/functions/firebase-functions.auth#authuserrecord)\nobject. For example, you can get the user's email and display name as shown:\n\n\u003cbr /\u003e\n\n```gdscript\nconst email = user.email; // The email of the user.\nconst displayName = user.displayName; // The display name of the user.https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Node-1st-gen/quickstarts/email-users/functions/index.js#L48-L49\n```\n\n\u003cbr /\u003e\n\nTrigger a function on user deletion\n\nJust as you can trigger a function on user creation, you can\nrespond to user deletion events. Use the\n[`functions.auth.user().onDelete()`](/docs/reference/functions/firebase-functions.auth.userbuilder#authuserbuilderondelete)\nevent handler as shown:\n\n\u003cbr /\u003e\n\n```gdscript\nexports.sendByeEmail = functions.auth.user().onDelete((user) =\u003e {\n // ...\n});\n```\n\n\u003cbr /\u003e\n\n| **Caution:** Deleting multiple users at once using the Firebase Admin SDK (for example, `admin.auth().deleteUsers([uid1, uid2])` in Node.js) does not fire user deletion events, so event handlers set up using `functions.auth.user().onDelete()` *will not be triggered*. Delete users one at a time if you want user deletion events to fire for each deleted user.\n\nTrigger blocking functions\n\nIf you've upgraded to Firebase Authentication with Identity Platform, you can extend Firebase Authentication using\n[blocking Cloud Functions](/docs/auth/extend-with-blocking-functions).\n\nBlocking functions let you execute custom code that modifies the result of a\nuser registering or signing in to your app. For example, you can prevent a user\nfrom authenticating if they don't meet certain criteria, or update a user's\ninformation before returning it to your client app."]]