Skip to content

feat: anonymous account upgrade with error handling #1247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Apr 29, 2025

Notes

  1. Set up auto upgrade anonymous account for:
  • Signing user in with credential
  • Creating user
  • Sign in with email link
  1. Created merge conflict error so we can pass back the credential to the user should it fail on email-already-in-use like in the current FirebaseUI Auth. This is logic is duplicated in a few place in previous implementation but is handled in one spot for FUIAuth SwiftUI.

Questions

  1. Do we want the logic for forcing same device? It isn't a configuration option currently in FUIAuth SwiftUI. See: https://github.com/firebase/FirebaseUI-iOS/blob/main/FirebaseEmailAuthUI/Sources/FUIEmailAuth.m#L829-L844. Personally, I think this might be overkill. At the moment, if email-link isn't in app storage, we throw an error here: https://github.com/firebase/FirebaseUI-iOS/pull/1247/files#diff-659d4c231d40710232200eb4482235de5964068a1395944bc32983fe0ed8670cR305. We could just push user back to email link sign-in View if it isn't present.
  2. Do we want to also link provider with email link? In the previous implementation, it does have this ability but only for Facebook as far as I can tell. It checks query param here: https://github.com/firebase/FirebaseUI-iOS/blob/main/FirebaseEmailAuthUI/Sources/FUIEmailAuth.m#L261-L270 but only for Facebook: https://github.com/firebase/FirebaseUI-iOS/blob/main/FirebaseEmailAuthUI/Sources/FUIEmailAuth.m#L296-L359

@russellwheatley russellwheatley changed the title chore: anonymous account upgrade question: anonymous account upgrade Apr 29, 2025
@russellwheatley russellwheatley marked this pull request as ready for review April 30, 2025 07:14
@russellwheatley russellwheatley changed the title question: anonymous account upgrade feat: anonymous account upgrade with error handling May 2, 2025
Copy link
Contributor

@morganchen12 morganchen12 left a comment

Choose a reason for hiding this comment

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

LGTM other than the one comment.

@@ -167,21 +173,37 @@ public final class AuthService {
}
}

public func handleAutoUpgradeAnonymousUser(credentials credentials: AuthCredential) async throws {
do {
try await currentUser?.link(with: credentials)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should handle the currentUser null state in a separate conditional, otherwise this do-catch has the possibility of executing nothing and returning no error. From a convenience perspective it may also be nice to pass the unwrapped user through to the AccoutMergeConflictContext so the consumer doesn't have to again unwrap currentUser.

In theory currentUser should never be null here, so throwing an error is appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

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

@morganchen12 - updated. I didn't add User to the exception as it produced an Xcode compiler error: Stored property 'user' of 'Sendable'-conforming struct 'AccountMergeConflictContext' has non-sendable type 'User'

It seems User is non-sendable.

Copy link
Contributor

Choose a reason for hiding this comment

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

A fix for that is in the pipeline in upstream Firebase, so maybe leave a TODO and just send the user's UID (String) for now?

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