Skip to content

Commit 27f3a61

Browse files
format
1 parent 2504703 commit 27f3a61

File tree

6 files changed

+31
-34
lines changed

6 files changed

+31
-34
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/AuthServiceError.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ public enum AuthServiceError: LocalizedError {
9898
case invalidEmailLink(String)
9999
case clientIdNotFound(String)
100100
case notConfiguredActionCodeSettings(String)
101-
101+
102102
/// Simple reauthentication required (Google, Apple, Facebook, Twitter, etc.)
103103
/// Can be passed directly to `reauthenticate(context:)` method
104104
case simpleReauthenticationRequired(context: ReauthContext)
105-
105+
106106
/// Email reauthentication required - user must handle password prompt externally
107107
case emailReauthenticationRequired(context: ReauthContext)
108-
108+
109109
/// Phone reauthentication required - user must handle SMS verification flow externally
110110
case phoneReauthenticationRequired(context: ReauthContext)
111-
111+
112112
case invalidCredentials(String)
113113
case signInFailed(underlying: Error)
114114
case accountConflict(AccountConflictContext)

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -703,34 +703,34 @@ public extension AuthService {
703703
/// - Throws: Error if reauthentication fails or provider is not found
704704
/// - Note: This only works for providers that can automatically obtain credentials.
705705
/// For email/phone, handle the flow externally and use `reauthenticate(with:)`
706-
public func reauthenticate(context: ReauthContext) async throws {
706+
func reauthenticate(context: ReauthContext) async throws {
707707
guard let user = currentUser else {
708708
throw AuthServiceError.noCurrentUser
709709
}
710-
710+
711711
// Find the provider and get credential
712712
guard let matchingProvider = providers.first(where: { $0.id == context.providerId }),
713713
let credentialProvider = matchingProvider.provider as? CredentialAuthProviderSwift else {
714714
throw AuthServiceError.providerNotFound("No provider found for \(context.providerId)")
715715
}
716-
716+
717717
let credential = try await credentialProvider.createAuthCredential()
718718
try await user.reauthenticate(with: credential)
719719
currentUser = auth.currentUser
720720
}
721-
721+
722722
/// Reauthenticates with a pre-obtained credential
723723
/// Use this when you've handled getting the credential yourself (email/phone)
724724
/// - Parameter credential: The authentication credential to use for reauthentication
725725
/// - Throws: Error if reauthentication fails
726-
public func reauthenticate(with credential: AuthCredential) async throws {
726+
func reauthenticate(with credential: AuthCredential) async throws {
727727
guard let user = currentUser else {
728728
throw AuthServiceError.noCurrentUser
729729
}
730730
try await user.reauthenticate(with: credential)
731731
currentUser = auth.currentUser
732732
}
733-
733+
734734
/// Internal helper to create reauth context and throw appropriate error
735735
/// - Throws: Appropriate `AuthServiceError` based on the provider type
736736
private func requireReauthentication() async throws -> Never {
@@ -741,7 +741,7 @@ public extension AuthService {
741741
phoneNumber: currentUser?.phoneNumber,
742742
email: currentUser?.email
743743
)
744-
744+
745745
switch providerId {
746746
case EmailAuthProviderID:
747747
throw AuthServiceError.emailReauthenticationRequired(context: context)
@@ -782,7 +782,7 @@ public extension AuthService {
782782

783783
return providerId
784784
}
785-
785+
786786
/// Get a user-friendly display name for a provider ID
787787
/// - Parameter providerId: The provider ID from Firebase Auth
788788
/// - Returns: A user-friendly name for the provider

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/ReauthenticationHelpers.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,17 @@ import FirebaseAuth
2323
/// - operation: The operation to execute
2424
/// - Throws: Rethrows errors from the operation or reauthentication process
2525
@MainActor
26-
public func withReauthenticationIfNeeded(
27-
authService: AuthService,
28-
coordinator: ReauthenticationCoordinator,
29-
operation: @escaping () async throws -> Void
30-
) async throws {
26+
public func withReauthenticationIfNeeded(authService: AuthService,
27+
coordinator: ReauthenticationCoordinator,
28+
operation: @escaping () async throws
29+
-> Void) async throws {
3130
do {
3231
try await operation()
3332
} catch let error as NSError {
3433
// Check if reauthentication is needed
3534
if error.domain == AuthErrorDomain,
3635
error.code == AuthErrorCode.requiresRecentLogin.rawValue ||
3736
error.code == AuthErrorCode.userTokenExpired.rawValue {
38-
3937
// Determine the provider context
4038
let providerId = try await authService.getCurrentSignInProvider()
4139
let context = ReauthContext(
@@ -44,18 +42,18 @@ public func withReauthenticationIfNeeded(
4442
phoneNumber: authService.currentUser?.phoneNumber,
4543
email: authService.currentUser?.email
4644
)
47-
45+
4846
// Handle based on provider type
4947
switch providerId {
5048
case PhoneAuthProviderID, EmailAuthProviderID:
5149
// For email/phone, use coordinator to handle UI flow
5250
try await coordinator.requestReauth(context: context)
53-
51+
5452
default:
5553
// For simple providers (Google, Apple, etc.), AuthService can handle it directly
5654
try await authService.reauthenticate(context: context)
5755
}
58-
56+
5957
// Retry the operation after successful reauth
6058
try await operation()
6159
} else {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/PasswordPromptView.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ import SwiftUI
2121
public struct EmailReauthView {
2222
@Environment(AuthService.self) private var authService
2323
@Environment(\.reportError) private var reportError
24-
24+
2525
let email: String
2626
let coordinator: ReauthenticationCoordinator
27-
27+
2828
@State private var password = ""
2929
@State private var isLoading = false
3030
@State private var error: AlertError?
31-
31+
3232
private func verifyPassword() {
3333
guard !password.isEmpty else { return }
34-
34+
3535
Task { @MainActor in
3636
isLoading = true
3737
do {
@@ -64,24 +64,24 @@ extension EmailReauthView: View {
6464
Image(systemName: "lock.circle.fill")
6565
.font(.system(size: 60))
6666
.foregroundColor(.blue)
67-
67+
6868
Text("Confirm Password")
6969
.font(.title)
7070
.fontWeight(.bold)
71-
71+
7272
Text("For security, please enter your password")
7373
.font(.body)
7474
.foregroundColor(.secondary)
7575
.multilineTextAlignment(.center)
7676
}
7777
.padding()
78-
78+
7979
VStack(spacing: 20) {
8080
Text("Email: \(email)")
8181
.font(.caption)
8282
.frame(maxWidth: .infinity, alignment: .leading)
8383
.padding(.bottom, 8)
84-
84+
8585
AuthTextField(
8686
text: $password,
8787
label: authService.string.passwordFieldLabel,
@@ -97,7 +97,7 @@ extension EmailReauthView: View {
9797
)
9898
.submitLabel(.done)
9999
.accessibilityIdentifier("email-reauth-password-field")
100-
100+
101101
Button(action: verifyPassword) {
102102
if isLoading {
103103
ProgressView()
@@ -112,13 +112,13 @@ extension EmailReauthView: View {
112112
.buttonStyle(.borderedProminent)
113113
.disabled(password.isEmpty || isLoading)
114114
.accessibilityIdentifier("confirm-password-button")
115-
115+
116116
Button(authService.string.cancelButtonLabel) {
117117
coordinator.reauthCancelled()
118118
}
119119
}
120120
.padding(.horizontal)
121-
121+
122122
Spacer()
123123
}
124124
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/PhoneReauthView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ extension PhoneReauthView: View {
133133
Button(authService.string.cancelButtonLabel) {
134134
coordinator.reauthCancelled()
135135
}
136-
137136
}
138137
.padding(.horizontal)
139138
} else {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/ReauthenticationModifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct ReauthenticationModifier: ViewModifier {
7878
Task {
7979
do {
8080
guard let context = coordinator.reauthContext else { return }
81-
81+
8282
// For simple providers (Google, Apple, etc.), call reauthenticate with context
8383
try await authService.reauthenticate(context: context)
8484
coordinator.reauthCompleted()

0 commit comments

Comments
 (0)