创建新用户时,我需要向用户发送一封验证电子邮件,以确保他们拥有该电子邮件地址。我的代码需要重新排列,以便Auth.auth()。currentUser?.sendEmailVerification调用在用户创建后立即在登录调用之前进行。我不确定1)将其放置在何处,2)验证是否已经进行验证所需的代码,以及3)成功验证后登录用户。
func signUp(with email: String, password: String, firstName: String, lastName: String) {
self.presentActivityView()
Auth.auth().createUser(withEmail: email, password: password) {[unowned self] (user, error) in
DispatchQueue.main.async { [unowned self] in
self.dismissActivityView()
if let err = error {
self.addAlertController(title: "Error!", message: err.localizedDescription)
} else {
let changeReq = Auth.auth().currentUser?.createProfileChangeRequest()
changeReq?.displayName = firstName + " " + lastName
if let url = self.profilePicURLString {
changeReq?.photoURL = URL(string: url)
}
changeReq?.commitChanges(completion: { (error) in
if error == nil {
//Profile updated successfully
}else {
//Profile not updated successfully
}
})
Auth.auth().currentUser?.sendEmailVerification(completion: { (error) in
if error == nil {
//Verification initiated successfully
}else {
print("Error: \(error)")
}
})
let vc = MainStoryboard.instantiateViewController(withIdentifier: "SNStoryFeedController") as! SNStoryFeedController
let nc = UINavigationController(rootViewController: vc)
UIApplication.shared.keyWindow?.rootViewController = nc
}
}
}
}