Skip to content

Commit 45dc2bb

Browse files
fix: catch MFA error
1 parent 6a74398 commit 45dc2bb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public enum SignInOutcome: @unchecked Sendable {
5959
case signedIn(AuthDataResult?)
6060
}
6161

62-
63-
6462
@MainActor
6563
private final class AuthListenerManager {
6664
private var authStateHandle: AuthStateDidChangeListenerHandle?
@@ -236,6 +234,7 @@ public final class AuthService {
236234
}
237235
do {
238236
let result = try await currentUser?.link(with: credentials)
237+
signedInCredential = credentials
239238
updateAuthenticationState()
240239
return .signedIn(result)
241240
} catch let error as NSError {
@@ -263,11 +262,18 @@ public final class AuthService {
263262
updateAuthenticationState()
264263
return .signedIn(result)
265264
}
266-
} catch {
265+
} catch let error as NSError {
267266
authenticationState = .unauthenticated
268-
errorMessage = string.localizedErrorMessage(
269-
for: error
270-
)
267+
errorMessage = string.localizedErrorMessage(for: error)
268+
269+
// Check if this is an MFA required error
270+
if error.code == AuthErrorCode.secondFactorRequired.rawValue {
271+
if let resolver = error
272+
.userInfo[AuthErrorUserInfoMultiFactorResolverKey] as? MultiFactorResolver {
273+
return handleMFARequiredError(resolver: resolver)
274+
}
275+
}
276+
271277
throw error
272278
}
273279
}
@@ -527,7 +533,7 @@ public extension AuthService {
527533
}
528534
}
529535

530-
// MARK: - MFA Methods (Placeholder implementations)
536+
// MARK: - MFA Methods
531537

532538
public extension AuthService {
533539
func startMfaEnrollment(type: SecondFactorType, accountName: String? = nil,

0 commit comments

Comments
 (0)