0Pricing
Firebase Auth & Realtime Database Apps · درس

دمج تسجيل الدخول باستخدام Apple

أضف Sign in with Apple إلى تطبيق Firebase، واستوفِ متطلب Apple App Store لتسجيلات الدخول عبر الشبكات الاجتماعية، وتعامل بشكل صحيح مع ترحيل البريد الإلكتروني الذي يركز على الخصوصية لدى Apple.

دمج تسجيل الدخول باستخدام Apple درس مجاني في Firebase Auth & Realtime Database Apps على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Firebase Auth & Realtime Database Apps، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Firebase Auth & Realtime Database Apps 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Why Apple Sign-In

If your iOS app offers any third-party social login (Google, Facebook, etc.), Apple's App Store guidelines require you to also offer Sign in with Apple. Beyond compliance, it is a fast, privacy-respecting option users trust.

How It Differs

Apple Sign-In has unique traits compared to other providers:

  • Users can hide their real email via a private relay address
  • Name and email are only returned on the first sign-in
  • Requires an Apple Developer account to configure

Enabling the Provider

In the Firebase console open Authentication > Sign-in method and enable Apple. For web you must also supply your Apple Service ID, Team ID, Key ID, and a private key generated in the Apple Developer portal.

Configuring the OAuth Provider

On the web you use Firebase's OAuthProvider with the Apple provider ID and request the scopes you need.

import { OAuthProvider } from 'firebase/auth';

const provider = new OAuthProvider('apple.com');
provider.addScope('email');
provider.addScope('name');

Triggering the Sign-In

Use signInWithPopup (or redirect on mobile web) to launch the Apple flow and receive a Firebase user.

import { getAuth, signInWithPopup } from 'firebase/auth';

const result = await signInWithPopup(getAuth(), provider);
const user = result.user;
console.log('Signed in as', user.uid);

Capturing Name on First Sign-In

Apple sends the user's full name only once, on the very first authorization. Persist it immediately, because subsequent sign-ins will not include it.

const credential = OAuthProvider.credentialFromResult(result);
const fullName = result._tokenResponse?.displayName;
if (fullName) saveProfileName(user.uid, fullName);

The Private Email Relay

If a user chooses to hide their email, Apple returns a relay address like abc123@privaterelay.appleid.com. Email sent to it is forwarded to the user.

  • Treat it as a valid, stable email
  • Do not require the 'real' address

Account Linking

A user may sign in with Apple after previously using email/password with the same address. Use Firebase account linking to merge identities into a single account rather than creating duplicates.

import { linkWithCredential } from 'firebase/auth';

const cred = OAuthProvider.credentialFromResult(result);
await linkWithCredential(existingUser, cred);

Native iOS Considerations

In a native iOS app you generate a nonce and pass Apple's identity token plus that nonce to Firebase. The nonce protects against replay attacks and is required by Firebase for native Apple credentials.

Handling Cancellation

Users can dismiss the Apple sheet. This surfaces as an error you should treat as a silent no-op, not a failure to display loudly.

try {
  await signInWithPopup(getAuth(), provider);
} catch (e) {
  if (e.code === 'auth/popup-closed-by-user') return;
  showError('Sign-in failed, please try again.');
}

Testing and Review

Apple reviewers actively check that Sign in with Apple is offered when other social logins exist. Test the full flow, including the hide-email path, before submitting your app for review.

Quick Check

Test your understanding of Apple Sign-In.

Recap

You can now add Apple Sign-In correctly.

  • Required when other social logins are offered on iOS
  • Configure the provider with Service/Team/Key IDs
  • Capture the name on first sign-in only
  • Support the private email relay
  • Use nonces natively and link duplicate accounts

الأسئلة الشائعة

هل درس «دمج تسجيل الدخول باستخدام Apple» مجاني؟

نعم — نص درس «دمج تسجيل الدخول باستخدام Apple» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Firebase Auth & Realtime Database Apps، انتقل إلى CoddyKit PRO. تتضمن دورة Firebase Auth & Realtime Database Apps 4 دروس في المجموع.

ماذا ستتعلم في «دمج تسجيل الدخول باستخدام Apple»؟

أضف Sign in with Apple إلى تطبيق Firebase، واستوفِ متطلب Apple App Store لتسجيلات الدخول عبر الشبكات الاجتماعية، وتعامل بشكل صحيح مع ترحيل البريد الإلكتروني الذي يركز على الخصوصية لدى Apple. تتمرن على Firebase Auth & Realtime Database Apps مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Firebase Auth & Realtime Database Apps؟

لا تُشترط خبرة سابقة. Firebase Auth & Realtime Database Apps على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «دمج تسجيل الدخول باستخدام Apple»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Firebase Auth & Realtime Database Apps هذا؟

نعم. كل درس في Firebase Auth & Realtime Database Apps يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. دمج تسجيل الدخول باستخدام Google
  2. المصادقة باستخدام Facebook وGitHub
  3. المصادقة المجهولة والمخصصة
  4. دمج تسجيل الدخول باستخدام Apple
← العودة إلى Firebase Auth & Realtime Database Apps