I'm new to firebase, singing with gmail on main view. after user singing, I'm saving the userinfo based on documentId, if the user already existed(already logged with gmail) person no need to save the information just update information of existed. So I tried some of the code, but I will not achieved what I'm expecting.
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error{
print(error.localizedDescription)
return
}
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: (authentication.idToken)!, accessToken: (authentication.accessToken)!)
Auth.auth().signIn(with: credential, completion: { (user, error) in
if let error = error {
print("Login erro \(error.localizedDescription)")
return
}
Here I check all document id in firestore
self.db.collection("pruser").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
// print("\(document.documentID) => \(document.data())")
print("\(document.documentID)")
Here I have to check with existed Document id's and current user Document id. If already existed update info, if not set the values on Document Id but when try with this code
self.ref = self.db.collection("pruser").document()
let doc = self.ref?.documentID
print("printdoucment id ",doc!)
}
}
}
}
userid: vnRsxNjJePfwRcAWOLy1iByhV352
Doucment id: PKKLapD9xE9kNNvntI8XuserId: vnRsxNjJePfwRcAWOLy1iByhV352
Doucment id: pxjiVXEgbZgFke3Mijk5
when I logged with existed email also documentid coming different, every login time DocumentId is coming different how achieve this issue? 