Is there a way in Firebase to verify a user's email prior to adding the user to the database? My ultimate goal is to create a SignUp form where the user first enters the email address, then presses a "Verify Email address" button. At this point the verification email will be sent and the user will follow the link from within to confirm the email address. Now, when going back to the app, the user will have a continue button, and if the the email is not verified, the user will not be able to register, if contrary, the user will be able to register.
How do I go about this? So far all the documentation says that I must createUser so then I can use currentUser.sendEmailVerification, but obviously, I do not want create a user, before verification. I also thought about using a completion block, but I am not sure how to work that out, because the registration would have to be postponed until the user presses the continue button.
Thanks
Auth.auth().createUser(withEmail: email, password: password, completion: {(user: User?, error) in
if error != nil {
print(error!)
return
}
guard let uid = user?.uid else {
return
}
let ref = Database.database().reference(fromURL: "https://project/")
let values = [
"email": email,
"userName": userName,
"name": name,
"birthDate": birthDate,
"phoneNumber": phoneNumber]
let userReference = ref.child("users").child(uid)
userReference.updateChildValues(values, withCompletionBlock: {(err, ref) in
if err != nil{
print(err!)
return
}
print("Successfully added user to database")
})
let usedUserReference = ref.child("users-Used").child(userName)
usedUserReference.setValue(uid, withCompletionBlock: {(err, ref) in
if err != nil{
print(err!)
return
}
print("Successfully added user to cannot be used-again list")
})
})