I have a Firebase Auth that stores the users, but it also builds a collection of users in the Cloud Firestore database. I can grab the users first name, but the problem I have is that it is always the last user that was added.
here is my function in swift
func welcomeName() {
let db = Firestore.firestore()
if let userId = Auth.auth().currentUser?.uid {
var userName = db.collection("users").getDocuments() { (snapshot, error) in
if let error = error {
print("Error getting documents: \(error)")
} else {
//do something
for document in snapshot!.documents {
var welcomeName = document["firstname"] as! String
self.welcomeLabel.text = "Hey, \(welcomeName) welcome!"
}
}
}
}
}
in firebase cloud my users are stored as so
start collection is "users"
add document is the autoID
then collection is
firstname "Jane"
lastname "Doe"
uid "IKEPa1lt1JX8gXxGkP4FAulmmZC2"
any ideas?