I am creating an iPhone app in swift 4.0. I'm connecting over to Firestore, which currently works. The problem that I'm having is that a random character is document is created each time a user is authenticated. I want to change this so the email address is the registered document in the DB so the next time I login with the same credentials its uses the same document.
let databaseRef = Database.database().reference(fromURL: “*****************”)
let storage = Storage.storage().reference()
let db = Firestore.firestore()
var ref: DocumentReference? = nil
var handle: AuthStateDidChangeListenerHandle?
var checkBtnTitle:Bool = true
override func viewDidLoad() {
super.viewDidLoad()
if Auth.auth().currentUser != nil {
let currentUser = Auth.auth().currentUser
btnLogOut.title = "LogOut"
btnLogin.title = "Login"
var ref: DocumentReference? = nil
ref = db.collection("Solicitor").addDocument(data: [
"userID": currentUser?.email! as Any,
"Name": currentUser?.displayName as Any
]) { err in
if let err = err {
print("Error adding document: \(err)")
} else {
print("Document added with ID: \(ref!.documentID)")
}
}
} else {
btnLogOut.title = "Login"
btnLogin.title = ""
}
// google signin
GIDSignIn.sharedInstance()?.uiDelegate = self