Firebase Auth & Realtime Database Apps · บทเรียน

การผสานการเข้าสู่ระบบด้วย Apple

เพิ่มการเข้าสู่ระบบด้วย Apple ให้กับแอป Firebase ของคุณ ปฏิบัติตามข้อกำหนดของ App Store สำหรับการเข้าสู่ระบบผ่านโซเชียล และจัดการระบบส่งต่ออีเมลที่คำนึงถึงความเป็นส่วนตัวของ Apple อย่างถูกต้อง

บทเรียน 4 จาก 413 ขั้นตอน

การผสานการเข้าสู่ระบบด้วย Apple เป็นบทเรียน Firebase Auth & Realtime Database Apps ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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
เริ่มต้นได้ฟรี

เรียนรู้ Firebase Auth & Realtime Database Apps ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
11
บทเรียน
44

คำถามที่พบบ่อย

บทเรียน “การผสานการเข้าสู่ระบบด้วย Apple” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การผสานการเข้าสู่ระบบด้วย Apple” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Firebase Auth & Realtime Database Apps ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Firebase Auth & Realtime Database Apps มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การผสานการเข้าสู่ระบบด้วย Apple”

เพิ่มการเข้าสู่ระบบด้วย Apple ให้กับแอป Firebase ของคุณ ปฏิบัติตามข้อกำหนดของ App Store สำหรับการเข้าสู่ระบบผ่านโซเชียล และจัดการระบบส่งต่ออีเมลที่คำนึงถึงความเป็นส่วนตัวของ Apple อย่างถูกต้อง คุณปฏิบัติ Firebase Auth & Realtime Database Apps ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 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 ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การผสานรวมการเข้าสู่ระบบด้วย Google
  2. การยืนยันตัวตนด้วย Facebook และ GitHub
  3. การยืนยันตัวตนแบบไม่ระบุตัวตนและแบบกำหนดเอง
  4. การผสานการเข้าสู่ระบบด้วย Apple
← กลับไปที่ Firebase Auth & Realtime Database Apps