تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يمكنك السماح للمستخدمين بتسجيل الدخول إلى تطبيقك باستخدام موفّري مصادقة متعدّدين من خلال ربط بيانات اعتماد موفّر المصادقة بحساب مستخدم حالي.
يمكن التعرّف على المستخدمين من خلال معرّف مستخدم Firebase نفسه بغض النظر عن موفّر المصادقة الذي استخدموه لتسجيل الدخول. على سبيل المثال، يمكن للمستخدم الذي سجّل الدخول باستخدام كلمة مرور ربط حساب Google وتسجيل الدخول باستخدام أي من الطريقتين في المستقبل. أو يمكن لمستخدم مجهول ربط حساب على Facebook، ثم تسجيل الدخول باستخدام Facebook في وقت لاحق لمواصلة استخدام تطبيقك.
قبل البدء
أضِف إمكانية استخدام اثنين أو أكثر من مقدّمي خدمات المصادقة (بما في ذلك المصادقة بدون تحديد الهوية) إلى تطبيقك.
ربط بيانات اعتماد مقدّم خدمة المصادقة بحساب مستخدم
لربط بيانات اعتماد مقدّم خدمة المصادقة بحساب مستخدم حالي، اتّبِع الخطوات التالية:
سجِّل دخول المستخدم باستخدام أيّ موفّر أو طريقة مصادقة.
أكمِل خطوات تسجيل الدخول لمزوّد المصادقة الجديد حتى، ولكن بدون، استدعاء إحدى طرق firebase::auth::Auth::SignInWithCredential. على سبيل المثال، يمكنك الحصول على رمز تعريف Google للمستخدم أو رمز الدخول إلى Facebook أو عنوان البريد الإلكتروني وكلمة المرور.
احصل على firebase::auth::Credential لموفّر المصادقة الجديد:
مرِّر العنصر firebase::auth::Credential إلى الطريقة LinkWithCredential الخاصة بالمستخدم الذي سجّل الدخول:
// Link the new credential to the currently active user.firebase::auth::Usercurrent_user=auth->current_user();firebase::Future<firebase::auth::AuthResult>result=current_user.LinkWithCredential(credential);
سيتعذّر إجراء طلب إلى LinkWithCredential إذا كانت بيانات الاعتماد مرتبطة مسبقًا بحساب مستخدم آخر. في هذه الحالة، عليك التعامل مع دمج الحسابات والبيانات المرتبطة بها على النحو المناسب لتطبيقك:
// Gather data for the currently signed in User.firebase::auth::Usercurrent_user=auth->current_user();std::stringcurrent_email=current_user.email();std::stringcurrent_provider_id=current_user.provider_id();std::stringcurrent_display_name=current_user.display_name();std::stringcurrent_photo_url=current_user.photo_url();// Sign in with the new credentials.firebase::Future<firebase::auth::AuthResult>result=auth->SignInAndRetrieveDataWithCredential(credential);// To keep example simple, wait on the current thread until call completes.while(result.status()==firebase::kFutureStatusPending){Wait(100);}// The new User is now active.if(result.error()==firebase::auth::kAuthErrorNone){firebase::auth::User*new_user=*result.result();// Merge new_user with the user in details.// ...(void)new_user;}
في حال نجاح طلب LinkWithCredential، يمكن للمستخدم الآن تسجيل الدخول باستخدام أي مقدّم خدمة مصادقة مرتبط والوصول إلى بيانات Firebase نفسها.
إلغاء ربط مقدّم خدمة مصادقة بحساب مستخدم
يمكنك إلغاء ربط موفّر مصادقة بحساب، كي لا يتمكّن المستخدم من تسجيل الدخول باستخدام هذا الموفّر.
لإلغاء ربط مقدّم خدمة مصادقة بحساب مستخدم، مرِّر رقم تعريف مقدّم الخدمة إلى الطريقة Unlink. يمكنك الحصول على معرّفات مقدّمي خدمة المصادقة المرتبطين بمستخدم من خلال طلب ProviderData.
// Unlink the sign-in provider from the currently active user.firebase::auth::Usercurrent_user=auth->current_user();firebase::Future<firebase::auth::AuthResult>result=current_user.Unlink(providerId);
تاريخ التعديل الأخير: 2025-08-28 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-28 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["| **Important** : There is a [known issue](https://github.com/firebase/firebase-js-sdk/issues/7675) that prevents `linkWithCredentials()` from working correctly in some projects. See the issue report for a workaround and the status of a fix.\n\nYou can allow users to sign in to your app using multiple authentication\nproviders by linking auth provider credentials to an existing user account.\nUsers are identifiable by the same Firebase user ID regardless of the\nauthentication provider they used to sign in. For example, a user who signed in\nwith a password can link a Google account and sign in with either method in the\nfuture. Or, an anonymous user can link a Facebook account and then, later, sign\nin with Facebook to continue using your app.\n\nBefore you begin\n\nAdd support for two or more authentication providers (possibly including\nanonymous authentication) to your app.\n\nLink auth provider credentials to a user account\n\nTo link auth provider credentials to an existing user account:\n\n1. Sign in the user using any authentication provider or method.\n2. Complete the sign-in flow for the new authentication provider up to, but not including, calling one of the [`firebase::auth::Auth::SignInWithCredential`](/docs/reference/cpp/class/firebase/auth/auth#signinwithcredential) methods. For example, get the user's Google ID token, Facebook access token, or email and password.\n3. Get a `firebase::auth::Credential` for the new authentication provider:\n\n **Google Sign-In** \n\n ```c++\n firebase::auth::Credential credential =\n firebase::auth::GoogleAuthProvider::GetCredential(google_id_token,\n nullptr);\n ```\n **Facebook Login** \n\n ```c++\n firebase::auth::Credential credential =\n firebase::auth::FacebookAuthProvider::GetCredential(access_token);\n ```\n **Email-password sign-in** \n\n ```c++\n firebase::auth::Credential credential =\n firebase::auth::EmailAuthProvider::GetCredential(email, password);\n ```\n4. Pass the `firebase::auth::Credential` object to the signed-in user's\n `LinkWithCredential` method:\n\n ```c++\n // Link the new credential to the currently active user.\n firebase::auth::User current_user = auth-\u003ecurrent_user();\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n current_user.LinkWithCredential(credential);\n ```\n\n The call to `LinkWithCredential` will fail if the credentials are\n already linked to another user account. In this situation, you must handle\n merging the accounts and associated data as appropriate for your app: \n\n ```c++\n // Gather data for the currently signed in User.\n firebase::auth::User current_user = auth-\u003ecurrent_user();\n std::string current_email = current_user.email();\n std::string current_provider_id = current_user.provider_id();\n std::string current_display_name = current_user.display_name();\n std::string current_photo_url = current_user.photo_url();\n\n // Sign in with the new credentials.\n firebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n auth-\u003eSignInAndRetrieveDataWithCredential(credential);\n\n // To keep example simple, wait on the current thread until call completes.\n while (result.status() == firebase::kFutureStatusPending) {\n Wait(100);\n }\n\n // The new User is now active.\n if (result.error() == firebase::auth::kAuthErrorNone) {\n firebase::auth::User* new_user = *result.result();\n\n // Merge new_user with the user in details.\n // ...\n (void)new_user;\n }\n ```\n\nIf the call to `LinkWithCredential` succeeds, the user can now sign in using\nany linked authentication provider and access the same Firebase data.\n\nUnlink an auth provider from a user account\n\nYou can unlink an auth provider from an account, so that the user can no\nlonger sign in with that provider.\n\nTo unlink an auth provider from a user account, pass the provider ID to the\n`Unlink` method. You can get the provider IDs of the auth providers\nlinked to a user by calling [`ProviderData`](/docs/reference/cpp/class/firebase/auth/user#providerdata). \n\n```c++\n// Unlink the sign-in provider from the currently active user.\nfirebase::auth::User current_user = auth-\u003ecurrent_user();\nfirebase::Future\u003cfirebase::auth::AuthResult\u003e result =\n current_user.Unlink(providerId);\n```\n\nTroubleshooting\n\nIf you encounter errors when trying to link multiple accounts, see the\n[documentation on\nverified email addresses](https://firebase.google.com/docs/auth/users#verified_email_addresses)."]]