Я хотел бы добавить возможность отправлять проверочное письмо при регистрации. Как я могу вставить sendEmailVerificationWithCompletion внутри функции и внутри элемента RegistrationView? Большое спасибо :)
import SwiftUI
import FirebaseAuth
// Add code here:
static func createUser(withEmail email:String, name: String, password:String, completionHandler:@escaping (Result<Bool,Error>) -> Void) {
Auth.auth().createUser(withEmail: email, password: password) { (authResult, error) in
if let err = error {
completionHandler(.failure(err))
return
}
guard let _ = authResult?.user else {
completionHandler(.failure(error!))
return
}
let data = FBUser.dataDict(uid: authResult!.user.uid, name: name, email: authResult!.user.email!)
FBFirestore.mergeFBUser(data, uid: authResult!.user.uid) { (result) in
completionHandler(result)
}
completionHandler(.success(true))
}
}
//And add code here:
struct SignUpView: View {
var body: some View {
VStack(spacing: 20 ) {
Button(action: {
FBAuth.createUser(withEmail: self.user.email, name: self.user.fullname, password: self.user.password) { (result) in
switch result {
case .failure(let error):
self.errorString = error.localizedDescription
self.showError = true
case .success(_):
print("Account creation successful")
}
}
}) {
Text("Register")
}
}
}
}