Skip to content

Commit 3a583ba

Browse files
fix: remove createPhoneAuthCredential
1 parent 2769e03 commit 3a583ba

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

FirebaseSwiftUI/FirebasePhoneAuthSwiftUI/Sources/Services/PhoneAuthProviderAuthUI.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ public class PhoneProviderSwift: PhoneAuthProviderSwift {
3434
}
3535
}
3636

37-
// Create a phone auth credential with the verification details
38-
public func createPhoneAuthCredential(verificationID: String,
39-
verificationCode: String) -> AuthCredential {
40-
return PhoneAuthProvider.provider()
41-
.credential(withVerificationID: verificationID, verificationCode: verificationCode)
42-
}
43-
4437
// Present phone auth UI and wait for user to complete the flow
4538
@MainActor public func createAuthCredential() async throws -> AuthCredential {
4639
guard let presentingViewController = await (UIApplication.shared.connectedScenes
@@ -54,7 +47,10 @@ public class PhoneProviderSwift: PhoneAuthProviderSwift {
5447
return try await withCheckedThrowingContinuation { continuation in
5548
let phoneAuthView = PhoneAuthView(phoneProvider: self) { result in
5649
switch result {
57-
case .success(let credential):
50+
case .success(let verificationID, let verificationCode):
51+
// Create the credential here
52+
let credential = PhoneAuthProvider.provider()
53+
.credential(withVerificationID: verificationID, verificationCode: verificationCode)
5854
continuation.resume(returning: credential)
5955
case .failure(let error):
6056
continuation.resume(throwing: error)

FirebaseSwiftUI/FirebasePhoneAuthSwiftUI/Sources/Views/PhoneAuthView.swift

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public struct PhoneAuthView {
3535
@State private var verificationID = ""
3636
@State private var isProcessing = false
3737
let phoneProvider: PhoneAuthProviderSwift
38-
let completion: (Result<AuthCredential, Error>) -> Void
38+
let completion: (Result<(String, String), Error>) -> Void
3939

40-
public init(phoneProvider: PhoneAuthProviderSwift, completion: @escaping (Result<AuthCredential, Error>) -> Void) {
40+
public init(phoneProvider: PhoneAuthProviderSwift, completion: @escaping (Result<(String, String), Error>) -> Void) {
4141
self.phoneProvider = phoneProvider
4242
self.completion = completion
4343
}
@@ -161,23 +161,10 @@ extension PhoneAuthView: View {
161161
Button(action: {
162162
Task {
163163
isProcessing = true
164-
do {
165-
guard let phoneAuthProvider = phoneProvider as? PhoneProviderSwift else {
166-
errorMessage = "Invalid phone provider"
167-
isProcessing = false
168-
return
169-
}
170-
let credential = phoneAuthProvider.createPhoneAuthCredential(
171-
verificationID: verificationID,
172-
verificationCode: verificationCode
173-
)
174-
completion(.success(credential))
175-
showVerificationCodeInput = false
176-
dismiss()
177-
} catch {
178-
errorMessage = error.localizedDescription
179-
isProcessing = false
180-
}
164+
// Return the verification details to createAuthCredential
165+
completion(.success((verificationID, verificationCode)))
166+
showVerificationCodeInput = false
167+
dismiss()
181168
}
182169
}) {
183170
Text(authService.string.verifyPhoneNumberAndSignInLabel)
@@ -203,8 +190,8 @@ extension PhoneAuthView: View {
203190
let phoneProvider = PhoneProviderSwift()
204191
return PhoneAuthView(phoneProvider: phoneProvider) { result in
205192
switch result {
206-
case .success:
207-
print("Preview: Phone auth succeeded")
193+
case .success(let verificationID, let verificationCode):
194+
print("Preview: Got verification - ID: \(verificationID), Code: \(verificationCode)")
208195
case .failure(let error):
209196
print("Preview: Phone auth failed with error: \(error)")
210197
}

0 commit comments

Comments
 (0)