Di chuyển tính năng đăng nhập bằng đường liên kết email khỏi Đường liên kết động của Firebase (Android)
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.
Trước đây, tính năng xác thực bằng đường liên kết trong email dựa vào Firebase Dynamic Links. Tính năng này sẽ ngừng hoạt động vào ngày 25 tháng 8 năm 2025. Chúng tôi đã xuất bản một giải pháp thay thế trong Firebase Authentication Android SDK phiên bản 23.2.0 trở lên và Firebase BoM phiên bản 33.9.0 trở lên. Nếu ứng dụng của bạn sử dụng các đường liên kết kiểu cũ và bạn muốn sử dụng một phương thức thay thế để di chuyển ứng dụng, hãy xem phần Xác thực bằng Firebase bằng đường liên kết qua email trong Android để sử dụng hệ thống mới dựa trên Firebase Hosting.
Ngoài ra, nếu đang sử dụng SDK Android Firebase Authentication dưới phiên bản 20.0.0 (hoặc Firebase BoM dưới phiên bản 26.0.0) để quản lý các luồng OAuth bằng Firebase Authentication, bạn cần cập nhật lên SDK Authentication hoặc phiên bản BoM mới nhất (Authentication phiên bản 20.0.0 trở lên hoặc BoM phiên bản 26.0.0 trở lên) để tiếp tục quản lý các luồng OAuth trong Firebase Authentication.
Di chuyển miền Firebase Dynamic Links được liên kết sang miền Firebase Hosting
Trong tương lai, thay vì sử dụng miền Firebase Dynamic Links, Firebase Authentication sẽ sử dụng miền mặc định Firebase Hosting cho dự án của bạn để tạo đường liên kết cho đường liên kết trong email và các hành động liên kết ngoài băng tần khác trong ứng dụng di động. Điều này có nghĩa là bạn cũng cần cập nhật ứng dụng để sử dụng miền mặc định này làm miền được liên kết cho các đường liên kết xác thực email đến ứng dụng di động của bạn.
Hãy làm theo hướng dẫn sau để xử lý các đường liên kết từ miền mới và hướng dẫn Firebase Authentication bắt đầu sử dụng miền mới để tạo các đường liên kết đến ứng dụng di động từ nay về sau.
Nếu bạn muốn tiếp tục sử dụng bất kỳ miền Firebase Hosting tuỳ chỉnh nào hoặc thậm chí miền Firebase Dynamic Links tuỳ chỉnh làm miền được liên kết mới, hãy làm theo các bước phù hợp với miền mà bạn muốn sử dụng. Xin lưu ý rằng sau khi bạn hoàn tất hướng dẫn trong phần sau, tính năng liên kết sâu trên miền tuỳ chỉnh Firebase Dynamic Links sẽ bị xoá; chỉ miền đó vẫn còn để tạo đường liên kết trong email.
Định cấu hình ứng dụng Android để xử lý đường liên kết Firebase Hosting
Để xử lý các đường liên kết này từ ứng dụng Android, bạn cần chỉ định tên gói của ứng dụng trong phần cài đặt dự án Firebase của bảng điều khiển. Ngoài ra, bạn cần cung cấp SHA-1 và SHA-256 của chứng chỉ ứng dụng.
Nếu muốn các đường liên kết Firebase Hosting này chuyển hướng đến một hoạt động cụ thể, bạn sẽ cần định cấu hình một bộ lọc ý định trong tệp AndroidManifest.xml. Bộ lọc ý định phải bắt được các đường liên kết Firebase Hosting của miền. Trong AndroidManifest.xml:
Khi người dùng mở một đường liên kết lưu trữ có đường dẫn "/__/auth/links" và lược đồ cũng như máy chủ mà bạn chỉ định, ứng dụng của bạn sẽ bắt đầu hoạt động bằng bộ lọc ý định này để xử lý đường liên kết.
Định cấu hình dự án để sử dụng các đường liên kết mới
Khi đã sẵn sàng xử lý các đường liên kết đến miền mới, bạn có thể sử dụng Firebase Admin SDK để cập nhật cách bạn muốn tạo đường liên kết qua email và hướng dẫn hệ thống phụ trợ của chúng tôi bắt đầu tạo đường liên kết bằng miền Firebase Hosting mới.
import{getAuth}from'firebase-admin/auth';constupdateEmailAuthDomain=async()=>{constupdateRequest={mobileLinksConfig:{domain:'HOSTING_DOMAIN',},};constprojectConfigManager=getAuth().projectConfigManager();try{constresponse=awaitprojectConfigManager.updateProjectConfig(updateRequest);// Updated project configconsole.log('Project configuration updated successfully:',response);}catch(error){console.error('Error updating the project:',error);}};
Gửi và đổi đường liên kết trong email
Gửi đường liên kết đăng nhập bằng email như trước. Khi người dùng cuối nhấp vào đường liên kết, họ sẽ được chuyển hướng đến ứng dụng (nếu đã cài đặt) để hoàn tất quá trình đăng nhập.
Tuỳ chỉnh đường liên kết trên thiết bị di động
Bạn có thể sử dụng miền Firebase Hosting tuỳ chỉnh hoặc sử dụng lại miền Firebase Dynamic Links tuỳ chỉnh để làm miền mới cho đường liên kết đến thiết bị di động.
Bạn có thể sử dụng lại bất kỳ miền Firebase Dynamic Links nào làm miền tuỳ chỉnh. Tuy nhiên, mọi chức năng Firebase Dynamic Links sẽ không còn được hỗ trợ (ví dụ: người dùng không thể được chuyển hướng đến một cửa hàng ứng dụng nếu ứng dụng chưa được cài đặt trên thiết bị của họ).
Định cấu hình ứng dụng Android để xử lý đường liên kết Firebase Hosting (hướng dẫn trong phần trước ở trê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-05 UTC."],[],[],null,["Email link authentication previously relied on Firebase Dynamic Links, which will be\n[shut down on August 25, 2025](/support/dynamic-links-faq). We've published an\nalternative solution in the Firebase Authentication Android SDK version 23.2.0+ and\nFirebase BoM version 33.9.0+. If your app uses the old style links and you\nwant to use an alternative method for migrating your app, see\n[Authenticate with Firebase using Email Link in Android](/docs/auth/android/email-link-auth)\nto use the new Firebase Hosting based system.\n\nAlso, if you're using the **Firebase Authentication Android SDK below v20.0.0 (or the\nFirebase BoM below v26.0.0) to manage OAuth flows** with Firebase Authentication,\nyou'll need to update to the latest Authentication SDK or BoM version\n(Authentication v20.0.0+ or BoM v26.0.0+) in order to continue managing OAuth\nflows in Firebase Authentication.\n\nMigrate your associated Firebase Dynamic Links domain to a Firebase Hosting domain\n\nMoving forward, rather than using a Firebase Dynamic Links domain, Firebase Authentication\nwill use the Firebase Hosting default domain for your project to create\nlinks for email link and other out-of-band link actions in mobile apps. This\nmeans that your app will also need to be updated to use this default domain as\nthe associated domain for email authentication links to your mobile app.\n\nYou can follow the instructions in\n[Authenticate with Firebase Using Email Link in Android](/docs/auth/android/email-link-auth) to update your mobile app links\nto use the new automatically provisioned Firebase Hosting default domain.\n\nUse the following instructions to handle links from the new domain and to\ninstruct Firebase Authentication to start using the new domain to generate mobile app\nlinks going forward.\n\nIf you'd like to continue using any of your custom Firebase Hosting domains\nor even your custom Firebase Dynamic Links domain to be your new associated\ndomain, follow the steps that match the intended domain you'd like to use. Note\nthat after completing the instructions in the following section, the deep\nlinking feature on your Firebase Dynamic Links custom domain will be removed;\nonly the domain itself will remain for creating email links.\n\n1. **Configure your Android application to handle your Firebase Hosting link**\n\n 1. In order to handle these links from your Android application, your app's package name needs to be specified in the Firebase console project settings. In addition, the SHA-1 and SHA-256 of the application certificate need to be provided.\n 2. If you want these Firebase Hosting links to redirect to a specific\n activity, you will need to configure an intent filter in your\n `AndroidManifest.xml` file. The intent filter should catch\n Firebase Hosting links of your domain. In `AndroidManifest.xml`:\n\n \u003cintent-filter android:autoVerify=\"true\"\u003e\n \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n \u003cdata\n android:scheme=\"https\"\n android:host=\"PROJECT_ID.firebaseapp.com or a custom hosting domain\"\n android:pathPrefix=\"/__/auth/links\" /\u003e\n \u003c/intent-filter\u003e\n\n When users open a hosting link with the \"/__/auth/links\" path and the\n scheme and host you specify, your app will start the activity with this\n intent filter to handle the link.\n | **Important:** To ensure a seamless rollback, we recommend keeping your existing intent filter that handles Firebase Dynamic Links while trying out the Firebase Hosting link solution. The Firebase Dynamic Links solution will be available until August 25, 2025.\n2. **Configure your project to use the new links**\n\n When you're ready to handle the new domain links, you can use the\n [Firebase Admin SDK](/docs/admin/setup) to update how you want email links\n to be generated and instruct our backend to start generating links using\n the new Firebase Hosting domain. \n\n import { getAuth } from 'firebase-admin/auth';\n\n const updateEmailAuthDomain = async () =\u003e {\n const updateRequest = {\n mobileLinksConfig: {\n domain: 'HOSTING_DOMAIN',\n },\n };\n\n const projectConfigManager = getAuth().projectConfigManager();\n\n try {\n const response = await projectConfigManager.updateProjectConfig(updateRequest);\n // Updated project config\n console.log('Project configuration updated successfully:', response);\n } catch (error) {\n console.error('Error updating the project:', error);\n }\n };\n\n | **Important:** To rollback to the Firebase Dynamic Links while implementing and testing the backup solution, you should set the domain back to `FIREBASE_DYNAMIC_LINK`. The Firebase Dynamic Links solution will be available until August 25, 2025.\n3. **Send and redeem the email link**\n\n Send the email sign-in link as before. When the end user clicks the link,\n they will be redirected to the app if installed to complete the sign-in.\n\nCustomize your mobile links\n\nYou can use a custom Firebase Hosting domain or reuse your custom\nFirebase Dynamic Links domain to be your new mobile links domain.\n\nUse a custom Firebase Hosting domain\n\n1. Follow the [Firebase Hosting guide](/docs/hosting/custom-domain) to set up a custom domain.\n2. Configure your Android application to handle your Firebase Hosting link. (instructions in previous section above).\n3. [Send an authentication link to the user's email\n address](/docs/auth/android/email-link-auth#send_an_authentication_link_to_the_users_email_address) with an updated `ActionCodeSettings` object with a custom domain as `linkDomain`.\n\nRe-use your custom Firebase Dynamic Links domain\n\n1. You can re-use any of your Firebase Dynamic Links domains as your custom domain. However, any Firebase Dynamic Links functionality will no longer be supported (for example, users cannot be redirected to an app store if the app isn't installed on their device).\n2. Configure your Android application to handle your Firebase Hosting link (instructions in previous section above).\n3. [Send an authentication link to the user's email\n address](/docs/auth/android/email-link-auth#send_an_authentication_link_to_the_users_email_address) with an updated `ActionCodeSettings` object with a custom domain as `linkDomain`."]]