diff --git a/firefox-ios/Client/Frontend/Browser/Authenticator.swift b/firefox-ios/Client/Frontend/Browser/Authenticator.swift index 67e9ef106a3e..ba96f54fa1ab 100644 --- a/firefox-ios/Client/Frontend/Browser/Authenticator.swift +++ b/firefox-ios/Client/Frontend/Browser/Authenticator.swift @@ -55,22 +55,23 @@ class Authenticator { findMatchingCredentialsForChallenge( challenge, fromLoginsProvider: loginsHelper.logins - ) { credentials in + ) { result in DispatchQueue.main.async { - guard let credentials = credentials else { + switch result { + case .success(let credentials): + self.promptForUsernamePassword( + viewController, + credentials: credentials, + protectionSpace: challenge.protectionSpace, + loginsHelper: loginsHelper, + completionHandler: completionHandler + ) + case .failure: sendLoginsAutofillFailedTelemetry() completionHandler(.failure( LoginRecordError(description: "Unknown error when finding credentials") )) - return } - self.promptForUsernamePassword( - viewController, - credentials: credentials, - protectionSpace: challenge.protectionSpace, - loginsHelper: loginsHelper, - completionHandler: completionHandler - ) } } return @@ -90,13 +91,13 @@ class Authenticator { _ challenge: URLAuthenticationChallenge, fromLoginsProvider loginsProvider: RustLogins, logger: Logger = DefaultLogger.shared, - completionHandler: @escaping (URLCredential?) -> Void + completionHandler: @escaping (Result) -> Void ) { loginsProvider.getLoginsFor(protectionSpace: challenge.protectionSpace, withUsername: nil) { result in switch result { case .success(let logins): guard logins.count >= 1 else { - completionHandler(nil) + completionHandler(.success(nil)) return } @@ -133,9 +134,9 @@ class Authenticator { loginsProvider.updateLogin(id: login.id, login: new) { result in switch result { case .success: - completionHandler(credentials) - case .failure: - completionHandler(nil) + completionHandler(.success(credentials)) + case .failure(let error): + completionHandler(.failure(error)) } } return @@ -150,10 +151,10 @@ class Authenticator { category: .webview) } - completionHandler(credentials) + completionHandler(.success(credentials)) - case .failure: - completionHandler(nil) + case .failure(let error): + completionHandler(.failure(error)) } } }