-
Notifications
You must be signed in to change notification settings - Fork 485
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
russellwheatley
wants to merge
11
commits into
main
Choose a base branch
from
auto-upgrade-anonymous
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−24
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
699c134
chore: anonymous account upgrade
russellwheatley 52b92fb
implementation for handling errors when auto upgrading anonymous user
russellwheatley 5614990
email link sign-in
russellwheatley 89db7b0
checked - it does work
russellwheatley 7d75ca2
get anonymousId from continueUrl
russellwheatley 89e3b6f
create function for getting anonymous ID
russellwheatley 32d82c2
chore: check continurUrl is present before continuing
russellwheatley 3f796c6
chore: update message
russellwheatley fbd0d4f
removed unused logic for force same device for now
russellwheatley 086cb4e
Merge branch 'main' into auto-upgrade-anonymous
russellwheatley b26351c
throw exception if there is no currentUser. rm duplicate arg labels
russellwheatley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 23 additions & 6 deletions
29
FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/AuthServiceError.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,48 @@ | ||
|
||
import FirebaseAuth | ||
import SwiftUI | ||
|
||
public struct AccountMergeConflictContext: LocalizedError { | ||
public let credential: AuthCredential | ||
public let underlyingError: Error | ||
public let message: String | ||
|
||
public var errorDescription: String? { | ||
return message | ||
} | ||
} | ||
|
||
public enum AuthServiceError: LocalizedError { | ||
case invalidEmailLink | ||
case noCurrentUser | ||
case invalidEmailLink(String) | ||
case notConfiguredProvider(String) | ||
case clientIdNotFound(String) | ||
case notConfiguredActionCodeSettings | ||
case notConfiguredActionCodeSettings(String) | ||
case reauthenticationRequired(String) | ||
case invalidCredentials(String) | ||
case signInFailed(underlying: Error) | ||
case accountMergeConflict(context: AccountMergeConflictContext) | ||
|
||
public var errorDescription: String? { | ||
switch self { | ||
case .invalidEmailLink: | ||
return "Invalid sign in link. Most likely, the link you used has expired. Try signing in again." | ||
case .noCurrentUser: | ||
return "No user is currently signed in." | ||
case let .invalidEmailLink(description): | ||
return description | ||
case let .notConfiguredProvider(description): | ||
return description | ||
case let .clientIdNotFound(description): | ||
return description | ||
case .notConfiguredActionCodeSettings: | ||
return "ActionCodeSettings has not been configured for `AuthConfiguration.emailLinkSignInActionCodeSettings`" | ||
case let .notConfiguredActionCodeSettings(description): | ||
return description | ||
case let .reauthenticationRequired(description): | ||
return description | ||
case let .invalidCredentials(description): | ||
return description | ||
case let .signInFailed(underlying: error): | ||
return "Failed to sign in: \(error.localizedDescription)" | ||
case let .accountMergeConflict(context): | ||
return context.errorDescription | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 theAccoutMergeConflictContext
so the consumer doesn't have to again unwrapcurrentUser
.In theory
currentUser
should never be null here, so throwing an error is appropriate.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?