Skip to content

fix(ui_oauth_apple): upgrade anonymous users by linking the Apple credential - #730

Merged
Mastersam07 merged 2 commits into
mainfrom
fix/apple-upgrade-anonymous
Oct 21, 2026
Merged

Mastersam07 merged 2 commits into
mainfrom
fix/apple-upgrade-anonymous

Conversation

@Mastersam07

@Mastersam07 Mastersam07 commented Oct 20, 2026 •

Copy link
Copy Markdown

Description

AppleProvider.mobileSignIn only linked on AuthAction.link, ignoring shouldUpgradeAnonymous. An anonymous user signing in with Apple got a fresh account instead of being upgraded, losing their uid and data. It now links when upgrading, matching OAuthProvider.onCredentialReceived and the Twitter provider.

Following review, the link path also matches TwitterProvider's guards:

  • AuthAction.link with no signed in user reports a no-current-user error instead of null-shorting and leaving the button loading forever.
  • _onLinked reports a missing-credential error instead of force unwrapping a null credential.

Split out of #288 (original commit by @yoman07, authorship preserved). The Facebook half of #288 already landed in #553.

Tests

Two new cases in tests/integration_test/firebase_ui_oauth_apple/apple_sign_in_test.dart: an anonymous user links instead of signing in, and linking with no user reports AuthFailed. Both fail without the fix. All 8 Apple tests pass locally on macOS.

Known limitation

Apple now behaves like Google already does in one flow: a returning Apple user who is signed in anonymously on a new device gets credential-already-in-use, because the Apple account already belongs to another user. Previously Apple skipped linking, so that user was signed in but the anonymous user's data was silently dropped. Surfacing this as an upgrade conflict the app can resolve (as Android and iOS do) is tracked in #734, since it belongs in the shared auth flow for every provider.

Related Issues

Part of #253. It fixes the Apple half; #253 stays open until #734 handles upgrade conflicts.

Breaking Change

  • No, this is not a breaking change.

…dential

Apple sign in ignored shouldUpgradeAnonymous and always called signInWithProvider, so an anonymous user's uid and data were lost. Link instead, matching the other providers.

Split out of #288. Fixes #253.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the mobileSignIn method in AppleProvider to link the provider when shouldUpgradeAnonymous is true. A review comment highlights that if auth.currentUser is null, the operation will silently fail and leave the UI in an infinite loading state, and suggests explicitly handling this error state.

Comment thread packages/firebase_ui_oauth_apple/lib/src/provider.dart
@Mastersam07
Mastersam07 marked this pull request as draft October 20, 2026 11:55
… nothing to link

AuthAction.link with no signed in user null-shorted, and a null credential from linkWithProvider was force unwrapped inside .then. Both left the flow stuck loading. Report them through the listener, matching TwitterProvider, and cover anonymous upgrade and the no-user case in tests.
@Mastersam07
Mastersam07 marked this pull request as ready for review October 20, 2026 13:07

@demolaf demolaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR: the anonymous-upgrade check is repeated in each provider, and that drift is how #253 happened. iOS and Android each check it in one shared place, behind an opt-in flag. Worth an issue?

Comment thread packages/firebase_ui_oauth_apple/lib/src/provider.dart
@Mastersam07
Mastersam07 merged commit c7bcd11 into main Oct 21, 2026
22 checks passed
@demolaf
demolaf deleted the fix/apple-upgrade-anonymous branch October 21, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants