Skip to content

Commit 0fb6e66

Browse files
committed
Merge branch 'development' of https://github.com/firebase/FirebaseUI-iOS into feat/ui-fixes
2 parents 1b7d17a + d9e7b79 commit 0fb6e66

20 files changed

Lines changed: 641 additions & 356 deletions

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/AuthServiceError.swift

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,56 @@
1515
import FirebaseAuth
1616
import SwiftUI
1717

18-
public struct AccountMergeConflictContext: LocalizedError {
18+
/// Describes the specific type of account conflict that occurred
19+
public enum AccountConflictType: Equatable {
20+
/// Account exists with a different provider (e.g., user signed up with Google, trying to use
21+
/// email)
22+
/// Solution: Sign in with existing provider, then link the new credential
23+
case accountExistsWithDifferentCredential
24+
25+
/// The credential is already linked to another account
26+
/// Solution: User must sign in with that account or unlink the credential
27+
case credentialAlreadyInUse
28+
29+
/// Email is already registered with another method
30+
/// Solution: Sign in with existing method, then link if desired
31+
case emailAlreadyInUse
32+
33+
/// Trying to link anonymous account to an existing account
34+
/// Solution: Sign out of anonymous, then sign in with the credential
35+
case anonymousUpgradeConflict
36+
}
37+
38+
public struct AccountConflictContext: LocalizedError, Identifiable, Equatable {
39+
public let id = UUID()
40+
public let conflictType: AccountConflictType
1941
public let credential: AuthCredential
2042
public let underlyingError: Error
2143
public let message: String
22-
// TODO: - should make this User type once fixed upstream in firebase-ios-sdk. See: https://github.com/firebase/FirebaseUI-iOS/pull/1247#discussion_r2085455355
23-
public let uid: String?
44+
public let email: String?
45+
46+
/// Human-readable description of the conflict type
47+
public var conflictDescription: String {
48+
switch conflictType {
49+
case .accountExistsWithDifferentCredential:
50+
return "This account is already registered with a different sign-in method."
51+
case .credentialAlreadyInUse:
52+
return "This credential is already linked to another account."
53+
case .emailAlreadyInUse:
54+
return "This email address is already in use."
55+
case .anonymousUpgradeConflict:
56+
return "Cannot link anonymous account to an existing account."
57+
}
58+
}
2459

2560
public var errorDescription: String? {
2661
return message
2762
}
63+
64+
public static func == (lhs: AccountConflictContext, rhs: AccountConflictContext) -> Bool {
65+
// Compare by id since each AccountConflictContext instance is unique
66+
lhs.id == rhs.id
67+
}
2868
}
2969

3070
public enum AuthServiceError: LocalizedError {
@@ -35,7 +75,7 @@ public enum AuthServiceError: LocalizedError {
3575
case reauthenticationRequired(String)
3676
case invalidCredentials(String)
3777
case signInFailed(underlying: Error)
38-
case accountMergeConflict(context: AccountMergeConflictContext)
78+
case accountConflict(AccountConflictContext)
3979
case providerNotFound(String)
4080
case multiFactorAuth(String)
4181
case rootViewControllerNotFound(String)
@@ -64,7 +104,7 @@ public enum AuthServiceError: LocalizedError {
64104
return description
65105
case let .signInCancelled(description):
66106
return description
67-
case let .accountMergeConflict(context):
107+
case let .accountConflict(context):
68108
return context.errorDescription
69109
case let .providerNotFound(description):
70110
return description

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthConfiguration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import SwiftUI
1818

1919
public struct AuthConfiguration {
2020
public let logo: ImageResource?
21+
public let languageCode: String?
2122
public let shouldHideCancelButton: Bool
2223
public let interactiveDismissEnabled: Bool
2324
public let shouldAutoUpgradeAnonymousUsers: Bool
2425
public let customStringsBundle: Bundle?
25-
public let languageCode: String?
2626
public let tosUrl: URL?
2727
public let privacyPolicyUrl: URL?
2828
public let emailLinkSignInActionCodeSettings: ActionCodeSettings?
@@ -36,11 +36,11 @@ public struct AuthConfiguration {
3636

3737
public init(
3838
logo: ImageResource? = nil,
39+
languageCode: String? = nil,
3940
shouldHideCancelButton: Bool = false,
4041
interactiveDismissEnabled: Bool = true,
4142
shouldAutoUpgradeAnonymousUsers: Bool = false,
4243
customStringsBundle: Bundle? = nil,
43-
languageCode: String? = nil,
4444
tosUrl: URL? = nil,
4545
privacyPolicyUrl: URL? = nil,
4646
emailLinkSignInActionCodeSettings: ActionCodeSettings? = nil,

0 commit comments

Comments
 (0)