@@ -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