Skip to content

Commit ee4784c

Browse files
format
1 parent d18752f commit ee4784c

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/AuthServiceError.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ import SwiftUI
1717

1818
/// Describes the specific type of account conflict that occurred
1919
public enum AccountConflictType: Equatable {
20-
/// Account exists with a different provider (e.g., user signed up with Google, trying to use email)
20+
/// Account exists with a different provider (e.g., user signed up with Google, trying to use
21+
/// email)
2122
/// Solution: Sign in with existing provider, then link the new credential
2223
case accountExistsWithDifferentCredential
23-
24+
2425
/// The credential is already linked to another account
2526
/// Solution: User must sign in with that account or unlink the credential
2627
case credentialAlreadyInUse
27-
28+
2829
/// Email is already registered with another method
2930
/// Solution: Sign in with existing method, then link if desired
3031
case emailAlreadyInUse
31-
32+
3233
/// Trying to link anonymous account to an existing account
3334
/// Solution: Sign out of anonymous, then sign in with the credential
3435
case anonymousUpgradeConflict
@@ -42,10 +43,10 @@ public struct AccountConflictContext: LocalizedError, Identifiable, Equatable {
4243
public let message: String
4344
public let email: String?
4445
public let existingProviderIds: [String]?
45-
46+
4647
/// Indicates if this conflict occurred during anonymous user upgrade
4748
public let isAnonymousUpgrade: Bool
48-
49+
4950
/// Human-readable description of the conflict type
5051
public var conflictDescription: String {
5152
switch conflictType {
@@ -59,11 +60,11 @@ public struct AccountConflictContext: LocalizedError, Identifiable, Equatable {
5960
return "Cannot link anonymous account to an existing account."
6061
}
6162
}
62-
63+
6364
public var errorDescription: String? {
6465
return message
6566
}
66-
67+
6768
public static func == (lhs: AccountConflictContext, rhs: AccountConflictContext) -> Bool {
6869
// Compare by id since each AccountConflictContext instance is unique
6970
lhs.id == rhs.id

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public final class AuthService {
134134
public let passwordPrompt: PasswordPromptCoordinator = .init()
135135
public var currentMFARequired: MFARequired?
136136
private var currentMFAResolver: MultiFactorResolver?
137-
137+
138138
/// Current account conflict context - observe this to handle conflicts and update backend
139139
public private(set) var currentAccountConflict: AccountConflictContext?
140140

@@ -291,15 +291,15 @@ public final class AuthService {
291291
conflictType: conflictType,
292292
credential: credentials
293293
)
294-
294+
295295
// Store it for consumers to observe
296296
currentAccountConflict = context
297-
297+
298298
// Only set error alert if we're NOT auto-handling it
299299
if conflictType != .anonymousUpgradeConflict {
300300
updateError(message: context.message, underlyingError: error)
301301
}
302-
302+
303303
// Throw the specific error with context
304304
throw AuthServiceError.accountConflict(context)
305305
} else {
@@ -856,28 +856,28 @@ public extension AuthService {
856856
}
857857

858858
// MARK: - Account Conflict Helper Methods
859-
859+
860860
private func determineConflictType(from error: NSError) -> AccountConflictType? {
861861
switch error.code {
862862
case AuthErrorCode.accountExistsWithDifferentCredential.rawValue:
863-
return shouldHandleAnonymousUpgrade ? .anonymousUpgradeConflict : .accountExistsWithDifferentCredential
863+
return shouldHandleAnonymousUpgrade ? .anonymousUpgradeConflict :
864+
.accountExistsWithDifferentCredential
864865
case AuthErrorCode.credentialAlreadyInUse.rawValue:
865866
return shouldHandleAnonymousUpgrade ? .anonymousUpgradeConflict : .credentialAlreadyInUse
866867
case AuthErrorCode.emailAlreadyInUse.rawValue:
867-
return shouldHandleAnonymousUpgrade ? .anonymousUpgradeConflict :.emailAlreadyInUse
868+
return shouldHandleAnonymousUpgrade ? .anonymousUpgradeConflict : .emailAlreadyInUse
868869
default:
869870
return nil
870871
}
871872
}
872-
873-
private func createConflictContext(
874-
from error: NSError,
875-
conflictType: AccountConflictType,
876-
credential: AuthCredential
877-
) -> AccountConflictContext {
878-
let updatedCredential = error.userInfo[AuthErrorUserInfoUpdatedCredentialKey] as? AuthCredential ?? credential
873+
874+
private func createConflictContext(from error: NSError,
875+
conflictType: AccountConflictType,
876+
credential: AuthCredential) -> AccountConflictContext {
877+
let updatedCredential = error
878+
.userInfo[AuthErrorUserInfoUpdatedCredentialKey] as? AuthCredential ?? credential
879879
let email = error.userInfo[AuthErrorUserInfoEmailKey] as? String
880-
880+
881881
return AccountConflictContext(
882882
conflictType: conflictType,
883883
credential: updatedCredential,

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerView.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct AuthPickerView<Content: View> {
2525

2626
@Environment(AuthService.self) private var authService
2727
private let content: () -> Content
28-
28+
2929
// View-layer state for handling auto-linking flow
3030
@State private var pendingCredentialForLinking: AuthCredential?
3131
}
@@ -63,7 +63,8 @@ extension AuthPickerView: View {
6363
}
6464
.interactiveDismissDisabled(authService.configuration.interactiveDismissEnabled)
6565
}
66-
// View-layer logic: Handle account conflicts (auto-handle anonymous upgrade, store others for linking)
66+
// View-layer logic: Handle account conflicts (auto-handle anonymous upgrade, store others for
67+
// linking)
6768
.onChange(of: authService.currentAccountConflict) { _, conflict in
6869
handleAccountConflict(conflict)
6970
}
@@ -74,21 +75,21 @@ extension AuthPickerView: View {
7475
}
7576
}
7677
}
77-
78+
7879
/// View-layer logic: Handle account conflicts with type-specific behavior
7980
private func handleAccountConflict(_ conflict: AccountConflictContext?) {
8081
guard let conflict = conflict else { return }
81-
82+
8283
// Only auto-handle anonymous upgrade conflicts
8384
if conflict.conflictType == .anonymousUpgradeConflict {
8485
Task {
8586
do {
8687
// Sign out the anonymous user
8788
try await authService.signOut()
88-
89+
8990
// Sign in with the new credential
9091
_ = try await authService.signIn(credentials: conflict.credential)
91-
92+
9293
// Successfully handled - conflict and error are cleared automatically by reset()
9394
} catch {
9495
// Error will be shown via normal error handling
@@ -101,11 +102,11 @@ extension AuthPickerView: View {
101102
// Error modal will show for user to see and handle
102103
}
103104
}
104-
105+
105106
/// View-layer logic: Attempt to link pending credential after successful sign-in
106107
private func attemptAutoLinkPendingCredential() {
107108
guard let credential = pendingCredentialForLinking else { return }
108-
109+
109110
Task {
110111
do {
111112
try await authService.linkAccounts(credentials: credential)

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/ErrorAlertView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ struct ErrorAlertModifier: ViewModifier {
2828
if error.underlyingError is CancellationError {
2929
return false
3030
}
31-
31+
3232
// Don't show alert for anonymous upgrade conflicts (they're auto-handled)
3333
if let authError = error.underlyingError as? AuthServiceError,
34-
case .accountConflict(let context) = authError,
34+
case let .accountConflict(context) = authError,
3535
context.conflictType == .anonymousUpgradeConflict {
3636
return false
3737
}

0 commit comments

Comments
 (0)