1919// Created by Russell Wheatley on 14/05/2025.
2020//
2121
22+ import FirebaseAuth
2223import FirebaseAuthSwiftUI
2324import FirebaseCore
24- import FirebaseAuth
2525import SwiftUI
2626
2727@MainActor
@@ -36,7 +36,8 @@ public struct PhoneAuthView {
3636 let phoneProvider : PhoneAuthProviderSwift
3737 let completion : ( Result < ( String , String ) , Error > ) -> Void
3838
39- public init ( phoneProvider: PhoneAuthProviderSwift , completion: @escaping ( Result < ( String , String ) , Error > ) -> Void ) {
39+ public init ( phoneProvider: PhoneAuthProviderSwift ,
40+ completion: @escaping ( Result < ( String , String ) , Error > ) -> Void ) {
4041 self . phoneProvider = phoneProvider
4142 self . completion = completion
4243 }
@@ -50,7 +51,11 @@ extension PhoneAuthView: View {
5051 HStack {
5152 Spacer ( )
5253 Button ( action: {
53- completion ( . failure( NSError ( domain: " PhoneAuthError " , code: - 1 , userInfo: [ NSLocalizedDescriptionKey: " User cancelled " ] ) ) )
54+ completion ( . failure( NSError (
55+ domain: " PhoneAuthError " ,
56+ code: - 1 ,
57+ userInfo: [ NSLocalizedDescriptionKey: " User cancelled " ]
58+ ) ) )
5459 dismiss ( )
5560 } ) {
5661 Image ( systemName: " xmark.circle.fill " )
@@ -60,12 +65,12 @@ extension PhoneAuthView: View {
6065 }
6166 . padding ( . horizontal)
6267 . padding ( . top, 8 )
63-
68+
6469 if !isProcessing {
6570 Text ( " Sign in with Phone " )
6671 . font ( . title2)
6772 . bold ( )
68-
73+
6974 LabeledContent {
7075 TextField ( " Enter phone number " , text: $phoneNumber)
7176 . textInputAutocapitalization ( . never)
@@ -79,14 +84,14 @@ extension PhoneAuthView: View {
7984 . background ( Divider ( ) , alignment: . bottom)
8085 . padding ( . bottom, 4 )
8186 . padding ( . horizontal)
82-
87+
8388 if !errorMessage. isEmpty {
8489 Text ( errorMessage)
8590 . foregroundColor ( . red)
8691 . font ( . caption)
8792 . padding ( . horizontal)
8893 }
89-
94+
9095 Button ( action: {
9196 Task {
9297 isProcessing = true
@@ -109,7 +114,7 @@ extension PhoneAuthView: View {
109114 . padding ( [ . top, . bottom] , 8 )
110115 . padding ( . horizontal)
111116 . buttonStyle ( . borderedProminent)
112-
117+
113118 Spacer ( )
114119 } else {
115120 Spacer ( )
@@ -136,25 +141,25 @@ extension PhoneAuthView: View {
136141 }
137142 . padding ( . horizontal)
138143 . padding ( . top, 8 )
139-
144+
140145 Text ( " Enter Verification Code " )
141146 . font ( . title2)
142147 . bold ( )
143-
148+
144149 TextField ( " Verification Code " , text: $verificationCode)
145150 . keyboardType ( . numberPad)
146151 . padding ( )
147152 . background ( Color ( . systemGray6) )
148153 . cornerRadius ( 8 )
149154 . padding ( . horizontal)
150-
155+
151156 if !errorMessage. isEmpty {
152157 Text ( errorMessage)
153158 . foregroundColor ( . red)
154159 . font ( . caption)
155160 . padding ( . horizontal)
156161 }
157-
162+
158163 Button ( action: {
159164 Task {
160165 isProcessing = true
@@ -173,7 +178,7 @@ extension PhoneAuthView: View {
173178 . padding ( . horizontal)
174179 }
175180 . disabled ( verificationCode. isEmpty || isProcessing)
176-
181+
177182 Spacer ( )
178183 }
179184 . padding ( . vertical)
@@ -187,9 +192,9 @@ extension PhoneAuthView: View {
187192 let phoneProvider = PhoneProviderSwift ( )
188193 return PhoneAuthView ( phoneProvider: phoneProvider) { result in
189194 switch result {
190- case . success( let verificationID, let verificationCode) :
195+ case let . success( verificationID, verificationCode) :
191196 print ( " Preview: Got verification - ID: \( verificationID) , Code: \( verificationCode) " )
192- case . failure( let error) :
197+ case let . failure( error) :
193198 print ( " Preview: Phone auth failed with error: \( error) " )
194199 }
195200 }
0 commit comments