Skip to content

Commit e794818

Browse files
committed
Remove some of the thrown errors in favor of optionals
1 parent 61f2714 commit e794818

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

FirebaseAuth/Sources/Swift/AuthProvider/PhoneAuthProvider.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ import Foundation
236236
retryOnInvalidAppCredential: Bool,
237237
uiDelegate: AuthUIDelegate?,
238238
recaptchaVerifier: AuthRecaptchaVerifier) async throws
239-
-> String {
239+
-> String? {
240240
let request = SendVerificationCodeRequest(phoneNumber: phoneNumber,
241241
codeIdentity: CodeIdentity.empty,
242242
requestConfiguration: auth
@@ -269,7 +269,7 @@ import Foundation
269269
retryOnInvalidAppCredential: Bool,
270270
uiDelegate: AuthUIDelegate?,
271271
auditFallback: Bool = false) async throws
272-
-> String {
272+
-> String? {
273273
let codeIdentity = try await verifyClient(withUIDelegate: uiDelegate)
274274
let request = SendVerificationCodeRequest(phoneNumber: phoneNumber,
275275
codeIdentity: codeIdentity,
@@ -375,7 +375,7 @@ import Foundation
375375
multiFactorSession session: MultiFactorSession?,
376376
uiDelegate: AuthUIDelegate?,
377377
auditFallback: Bool = false) async throws
378-
-> String {
378+
-> String? {
379379
if let settings = auth.settings,
380380
settings.isAppVerificationDisabledForTesting {
381381
let request = SendVerificationCodeRequest(
@@ -413,20 +413,14 @@ import Foundation
413413
enrollmentInfo: startMFARequestInfo,
414414
requestConfiguration: auth.requestConfiguration)
415415
let response = try await auth.backend.call(with: request)
416-
guard let sessionInfo = response.phoneSessionInfo?.sessionInfo else {
417-
throw AuthErrorUtils.error(code: .missingMultiFactorInfo)
418-
}
419-
return sessionInfo
416+
return response.phoneSessionInfo?.sessionInfo
420417
} else {
421418
let request = StartMFASignInRequest(MFAPendingCredential: session.mfaPendingCredential,
422419
MFAEnrollmentID: session.multiFactorInfo?.uid,
423420
signInInfo: startMFARequestInfo,
424421
requestConfiguration: auth.requestConfiguration)
425422
let response = try await auth.backend.call(with: request)
426-
guard let sessionInfo = response.responseInfo.sessionInfo else {
427-
throw AuthErrorUtils.error(code: .multiFactorInfoNotFound)
428-
}
429-
return sessionInfo
423+
return response.responseInfo.sessionInfo
430424
}
431425
} catch {
432426
return try await handleVerifyErrorWithRetry(
@@ -446,7 +440,7 @@ import Foundation
446440
retryOnInvalidAppCredential: Bool,
447441
multiFactorSession session: MultiFactorSession?,
448442
uiDelegate: AuthUIDelegate?,
449-
auditFallback: Bool = false) async throws -> String {
443+
auditFallback: Bool = false) async throws -> String? {
450444
if (error as NSError).code == AuthErrorCode.invalidAppCredential.rawValue {
451445
if retryOnInvalidAppCredential {
452446
auth.appCredentialManager.clearCredential()

FirebaseAuth/Sources/Swift/Backend/RPC/SendVerificationTokenResponse.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ import Foundation
1616

1717
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
1818
struct SendVerificationCodeResponse: AuthRPCResponse {
19-
let verificationID: String
19+
let verificationID: String?
2020

2121
init(dictionary: [String: AnyHashable]) throws {
22-
guard let verificationID = dictionary["sessionInfo"] as? String else {
23-
throw AuthErrorUtils.unexpectedResponse(deserializedResponse: dictionary)
24-
}
25-
self.verificationID = verificationID
22+
verificationID = dictionary["sessionInfo"] as? String
2623
}
2724
}

0 commit comments

Comments
 (0)