Skip to content

Commit e07ef83

Browse files
format
1 parent af8a8de commit e07ef83

File tree

9 files changed

+92
-86
lines changed

9 files changed

+92
-86
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Auth/MultiFactor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public struct EnrollmentSession {
5757
public let expiresAt: Date
5858

5959
// Internal handle to finish TOTP
60-
internal let _totpSecret: AnyObject?
60+
let _totpSecret: AnyObject?
6161

6262
public enum EnrollmentStatus {
6363
case initiated
@@ -111,4 +111,4 @@ public struct MFARequired {
111111
public init(hints: [MFAHint]) {
112112
self.hints = hints
113113
}
114-
}
114+
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/AuthServiceError.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public enum AuthServiceError: LocalizedError {
3939
case invalidPhoneAuthenticationArguments(String)
4040
case providerNotFound(String)
4141
case multiFactorAuth(String)
42-
4342

4443
public var errorDescription: String? {
4544
switch self {
@@ -62,7 +61,7 @@ public enum AuthServiceError: LocalizedError {
6261
case let .providerNotFound(description):
6362
return description
6463
case let .invalidPhoneAuthenticationArguments(description):
65-
return description
64+
return description
6665
case let .multiFactorAuth(description):
6766
return description
6867
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct AuthConfiguration {
2525
public let emailLinkSignInActionCodeSettings: ActionCodeSettings?
2626
public let verifyEmailActionCodeSettings: ActionCodeSettings?
2727

28-
// MARK: - MFA Configuration
28+
// MARK: - MFA Configuration
2929

3030
public let mfaEnabled: Bool
3131
public let allowedSecondFactors: Set<SecondFactorType>

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public final class AuthService {
162162
func reset() {
163163
currentError = nil
164164
}
165-
165+
166166
func updateError(title: String = "Error", message: String) {
167167
currentError = AlertError(title: title, message: message)
168168
}
@@ -193,7 +193,8 @@ public final class AuthService {
193193
}
194194
}
195195

196-
public func handleAutoUpgradeAnonymousUser(credentials: AuthCredential) async throws -> SignInOutcome {
196+
public func handleAutoUpgradeAnonymousUser(credentials: AuthCredential) async throws
197+
-> SignInOutcome {
197198
if currentUser == nil {
198199
throw AuthServiceError.noCurrentUser
199200
}
@@ -227,7 +228,7 @@ public final class AuthService {
227228
updateAuthenticationState()
228229
return .signedIn(result)
229230
}
230-
} catch let error as NSError {
231+
} catch let error as NSError {
231232
authenticationState = .unauthenticated
232233
updateError(message: string.localizedErrorMessage(for: error))
233234

@@ -281,7 +282,7 @@ public extension AuthService {
281282
let provider = matchingProvider.provider as? DeleteUserSwift else {
282283
throw AuthServiceError.providerNotFound("No provider found for \(providerId)")
283284
}
284-
285+
285286
try await provider.deleteUser(user: user)
286287
}
287288
}
@@ -428,7 +429,6 @@ public extension AuthService {
428429
}
429430
}
430431

431-
432432
// MARK: - Phone Auth Sign In
433433

434434
public extension AuthService {
@@ -459,7 +459,7 @@ public extension AuthService {
459459
guard let user = currentUser else {
460460
throw AuthServiceError.noCurrentUser
461461
}
462-
462+
463463
do {
464464
let changeRequest = user.createProfileChangeRequest()
465465
changeRequest.photoURL = url
@@ -469,12 +469,12 @@ public extension AuthService {
469469
throw error
470470
}
471471
}
472-
472+
473473
func updateUserDisplayName(name: String) async throws {
474474
guard let user = currentUser else {
475475
throw AuthServiceError.noCurrentUser
476476
}
477-
477+
478478
do {
479479
let changeRequest = user.createProfileChangeRequest()
480480
changeRequest.displayName = name
@@ -498,7 +498,10 @@ public extension AuthService {
498498

499499
// Check if MFA is enabled in configuration
500500
guard configuration.mfaEnabled else {
501-
throw AuthServiceError.multiFactorAuth("MFA is not enabled in configuration, please enable `AuthConfiguration.mfaEnabled`")
501+
throw AuthServiceError
502+
.multiFactorAuth(
503+
"MFA is not enabled in configuration, please enable `AuthConfiguration.mfaEnabled`"
504+
)
502505
}
503506

504507
// Check if the requested factor type is allowed
@@ -522,7 +525,9 @@ public extension AuthService {
522525
} else if let session = session {
523526
continuation.resume(returning: session)
524527
} else {
525-
continuation.resume(throwing: AuthServiceError.multiFactorAuth("Failed to get MFA session for '\(type)'"))
528+
continuation
529+
.resume(throwing: AuthServiceError
530+
.multiFactorAuth("Failed to get MFA session for '\(type)'"))
526531
}
527532
}
528533
}
@@ -630,9 +635,11 @@ public extension AuthService {
630635
// Validate session state
631636
guard session.canProceed else {
632637
if session.isExpired {
633-
throw AuthServiceError.multiFactorAuth("Enrollment session has expired, cannot complete enrollment")
638+
throw AuthServiceError
639+
.multiFactorAuth("Enrollment session has expired, cannot complete enrollment")
634640
} else {
635-
throw AuthServiceError.multiFactorAuth("Enrollment session is not in a valid state for completion")
641+
throw AuthServiceError
642+
.multiFactorAuth("Enrollment session is not in a valid state for completion")
636643
}
637644
}
638645

@@ -704,7 +711,7 @@ public extension AuthService {
704711
throw AuthServiceError
705712
.reauthenticationRequired("Recent login required to perform this operation.")
706713
}
707-
714+
708715
if providerId == EmailAuthProviderID {
709716
guard let email = user.email else {
710717
throw AuthServiceError.invalidCredentials("User does not have an email address")
@@ -862,7 +869,7 @@ public extension AuthService {
862869

863870
do {
864871
let result = try await resolver.resolveSignIn(with: assertion)
865-
872+
866873
// After MFA resolution, result.credential is nil, so restore the original credential
867874
// that was used before MFA was triggered
868875
signedInCredential = result.credential ?? pendingMFACredential

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extension AuthPickerView: View {
6060
case .mfaEnrollment:
6161
MFAEnrolmentView()
6262
case .mfaResolution:
63-
MFAResolutionView()
63+
MFAResolutionView()
6464
case .authPicker:
6565
if authService.emailSignInEnabled {
6666
Text(authService.authenticationFlow == .signIn ? authService.string

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/ErrorAlertView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SwiftUI
1818
struct ErrorAlertModifier: ViewModifier {
1919
@Binding var error: AlertError?
2020
let okButtonLabel: String
21-
21+
2222
func body(content: Content) -> some View {
2323
content
2424
.alert(isPresented: Binding<Bool>(
@@ -48,10 +48,9 @@ public struct AlertError: Identifiable {
4848
public let id = UUID()
4949
public let title: String
5050
public let message: String
51-
51+
5252
public init(title: String = "Error", message: String) {
5353
self.title = title
5454
self.message = message
5555
}
5656
}
57-

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/MFAEnrolmentView.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ public struct MFAEnrolmentView {
169169

170170
private func copyToClipboard(_ text: String) {
171171
UIPasteboard.general.string = text
172-
173172

174173
// Show feedback
175174
showCopiedFeedback = true
@@ -180,25 +179,25 @@ public struct MFAEnrolmentView {
180179
showCopiedFeedback = false
181180
}
182181
}
183-
182+
184183
private func generateQRCode(from string: String) -> UIImage? {
185184
let data = Data(string.utf8)
186-
185+
187186
guard let filter = CIFilter(name: "CIQRCodeGenerator") else { return nil }
188187
filter.setValue(data, forKey: "inputMessage")
189188
filter.setValue("H", forKey: "inputCorrectionLevel")
190-
189+
191190
guard let ciImage = filter.outputImage else { return nil }
192-
191+
193192
// Scale up the QR code for better quality
194193
let transform = CGAffineTransform(scaleX: 10, y: 10)
195194
let scaledImage = ciImage.transformed(by: transform)
196-
195+
197196
let context = CIContext()
198197
guard let cgImage = context.createCGImage(scaledImage, from: scaledImage.extent) else {
199198
return nil
200199
}
201-
200+
202201
return UIImage(cgImage: cgImage)
203202
}
204203
}
@@ -518,7 +517,7 @@ extension MFAEnrolmentView: View {
518517
.aspectRatio(contentMode: .fit)
519518
.frame(width: 200, height: 200)
520519
.accessibilityIdentifier("qr-code-image")
521-
520+
522521
HStack(spacing: 6) {
523522
Image(systemName: "arrow.up.forward.app.fill")
524523
.font(.caption)

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/MFAResolutionView.swift

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseCore
1615
import FirebaseAuth
16+
import FirebaseCore
1717
import SwiftUI
1818

1919
private enum FocusableField: Hashable {
@@ -108,66 +108,66 @@ public struct MFAResolutionView {
108108
extension MFAResolutionView: View {
109109
public var body: some View {
110110
VStack(spacing: 24) {
111-
// Header
112-
VStack(spacing: 12) {
113-
Image(systemName: "lock.shield")
114-
.font(.system(size: 50))
115-
.foregroundColor(.blue)
111+
// Header
112+
VStack(spacing: 12) {
113+
Image(systemName: "lock.shield")
114+
.font(.system(size: 50))
115+
.foregroundColor(.blue)
116116

117-
Text("Two-Factor Authentication")
118-
.font(.largeTitle)
119-
.fontWeight(.bold)
120-
.accessibilityIdentifier("mfa-resolution-title")
117+
Text("Two-Factor Authentication")
118+
.font(.largeTitle)
119+
.fontWeight(.bold)
120+
.accessibilityIdentifier("mfa-resolution-title")
121121

122-
Text("Complete sign-in with your second factor")
123-
.font(.body)
124-
.foregroundColor(.secondary)
125-
.multilineTextAlignment(.center)
126-
}
127-
.padding(.horizontal)
122+
Text("Complete sign-in with your second factor")
123+
.font(.body)
124+
.foregroundColor(.secondary)
125+
.multilineTextAlignment(.center)
126+
}
127+
.padding(.horizontal)
128128

129-
// MFA Hints Selection (if multiple available)
130-
if let mfaRequired = mfaRequired, mfaRequired.hints.count > 1 {
131-
mfaHintsSelectionView(mfaRequired: mfaRequired)
132-
}
129+
// MFA Hints Selection (if multiple available)
130+
if let mfaRequired = mfaRequired, mfaRequired.hints.count > 1 {
131+
mfaHintsSelectionView(mfaRequired: mfaRequired)
132+
}
133133

134-
// Resolution Content
135-
if let hint = selectedHint {
136-
resolutionContent(for: hint)
137-
}
134+
// Resolution Content
135+
if let hint = selectedHint {
136+
resolutionContent(for: hint)
137+
}
138138

139-
// Action buttons
140-
VStack(spacing: 12) {
141-
// Complete Resolution Button
142-
Button(action: completeResolution) {
143-
HStack {
144-
if isLoading {
145-
ProgressView()
146-
.scaleEffect(0.8)
147-
}
148-
Text("Complete Sign-In")
139+
// Action buttons
140+
VStack(spacing: 12) {
141+
// Complete Resolution Button
142+
Button(action: completeResolution) {
143+
HStack {
144+
if isLoading {
145+
ProgressView()
146+
.scaleEffect(0.8)
149147
}
148+
Text("Complete Sign-In")
149+
}
150+
.frame(maxWidth: .infinity)
151+
.padding()
152+
.background(canCompleteResolution ? Color.blue : Color.gray)
153+
.foregroundColor(.white)
154+
.cornerRadius(8)
155+
}
156+
.disabled(!canCompleteResolution)
157+
.accessibilityIdentifier("complete-resolution-button")
158+
159+
// Cancel Button
160+
Button(action: cancelResolution) {
161+
Text("Cancel")
150162
.frame(maxWidth: .infinity)
151163
.padding()
152-
.background(canCompleteResolution ? Color.blue : Color.gray)
153-
.foregroundColor(.white)
164+
.background(Color.gray.opacity(0.2))
165+
.foregroundColor(.primary)
154166
.cornerRadius(8)
155-
}
156-
.disabled(!canCompleteResolution)
157-
.accessibilityIdentifier("complete-resolution-button")
158-
159-
// Cancel Button
160-
Button(action: cancelResolution) {
161-
Text("Cancel")
162-
.frame(maxWidth: .infinity)
163-
.padding()
164-
.background(Color.gray.opacity(0.2))
165-
.foregroundColor(.primary)
166-
.cornerRadius(8)
167-
}
168-
.accessibilityIdentifier("cancel-button")
169167
}
170-
.padding(.horizontal)
168+
.accessibilityIdentifier("cancel-button")
169+
}
170+
.padding(.horizontal)
171171
}
172172
.padding(.vertical, 20)
173173
}
@@ -368,7 +368,7 @@ private extension MFAHint {
368368
FirebaseOptions.dummyConfigurationForPreview()
369369
let authService = AuthService()
370370
authService.currentMFARequired = MFARequired(hints: [
371-
.phone(displayName: "Work Phone", uid: "phone-uid-1", phoneNumber: "+15551234567")
371+
.phone(displayName: "Work Phone", uid: "phone-uid-1", phoneNumber: "+15551234567"),
372372
])
373373
return MFAResolutionView().environment(authService)
374374
}
@@ -377,7 +377,7 @@ private extension MFAHint {
377377
FirebaseOptions.dummyConfigurationForPreview()
378378
let authService = AuthService()
379379
authService.currentMFARequired = MFARequired(hints: [
380-
.totp(displayName: "Authenticator App", uid: "totp-uid-1")
380+
.totp(displayName: "Authenticator App", uid: "totp-uid-1"),
381381
])
382382
return MFAResolutionView().environment(authService)
383383
}
@@ -387,7 +387,7 @@ private extension MFAHint {
387387
let authService = AuthService()
388388
authService.currentMFARequired = MFARequired(hints: [
389389
.phone(displayName: "Mobile", uid: "phone-uid-1", phoneNumber: "+15551234567"),
390-
.totp(displayName: "Google Authenticator", uid: "totp-uid-1")
390+
.totp(displayName: "Google Authenticator", uid: "totp-uid-1"),
391391
])
392392
return MFAResolutionView().environment(authService)
393393
}

0 commit comments

Comments
 (0)