Hi guys, I am working on the custom sign up and login tutorial. Everything works perfectly fine, except the Firestore. When I tried to store the first name and last name in the Firestore, it didn’t work, but the authentication works, the user can be created, but the data about first name and last name can not be stored in Firestore. I have no idea how to solve this problem, because there isn’t any error shows on the console. Could you please help me to solve this problem, any help will be appreciated!
//create cleaned version of the data
let firstName = FirstName.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let lastName = LastName.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let email = Email.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let password = Password.text!.trimmingCharacters(in: .whitespacesAndNewlines)
//create a user
Auth.auth().createUser(withEmail: email, password: password) { (result, err) in
//check for errors
if err != nil {
//there was an error creating the user
self.showError("Error creating user")
}else{
//user was created successfully, now store the first name and last name
let db = Firestore.firestore()
db.collection("users").addDocument(data: ["first_name":firstName, "last_name":lastName, "uid":result!.user.uid]) { (error) in
if error != nil{
self.showError("Error saving user data")
}else{
print("No error")
self.showError("No Error")
}
}
self.transitionToHome()
}