in Education by
this is my first question here, i hope you can help me. I've been trying to get a specific path for the current user logged into my app. I don't really now what i'm doing wrong so i'll paste my code here. func userRoleListener() { guard let user = Auth.auth().currentUser else { return } . Firestore.firestore().collection("users").document("sjbD5SvKTYHWBLhCqojs").getDocument { (snapshot, error) in if let data = snapshot?.data() { guard let isAdmin = data["isAdmin"] as? Bool else { return } if isAdmin { self.applyButton.isHidden = true } else { self.applyButton.isHidden = false } } } } This is my function to create a user. private func createUser() { guard let nameAndLastname = nameAndLastnameTextField.text , let email = emailTextField.text , let password = passwordTextField.text , !nameAndLastname.isEmpty , !email.isEmpty , !password.isEmpty else { simpleAlert(title: "Error", msg: "Debe completar todos los campos") return } let newUserReference = Firestore.firestore().collection("users").document() newUserReference.setData([ "nameAndLastname": nameAndLastname, "email": email, "password": password, "isAdmin": false, "timestamp": Timestamp() ]) } And this is my login action: @IBAction func signUpButtonPressed(_ sender: Any) { guard let email = emailTextField.text , let password = passwordTextField.text , !email.isEmpty , !password.isEmpty else { return } self.signUpButton.animateButton(shouldLoad: true, withMessage: "") Auth.auth().createUser(withEmail: email, password: password) { (user, error) in if let error = error { self.signUpButton.animateButton(shouldLoad: false, withMessage: "¡REGISTRAR!") debugPrint(error.localizedDescription) self.simpleAlert(title: "Error", msg: "Error al iniciar sesión, intente nuevamente en unos minutos") return } self.signUpButton.animateButton(shouldLoad: false, withMessage: "") self.createUser() self.presentClientStoryboard() } } And this is an image of my database: Database image JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you create a user with Firebase Authentication, Authentication will create a user and a user id for you in Firebase Auth (Not Firestore) So when you create your user in Firestore, you have to set the userID as document id, like below: @IBAction func signUpButtonPressed(_ sender: Any) { guard let email = emailTextField.text , let password = passwordTextField.text , !email.isEmpty , !password.isEmpty else { return } self.signUpButton.animateButton(shouldLoad: true, withMessage: "") Auth.auth().createUser(withEmail: email, password: password) { (user, error) in if let error = error { self.signUpButton.animateButton(shouldLoad: false, withMessage: "¡REGISTRAR!") debugPrint(error.localizedDescription) self.simpleAlert(title: "Error", msg: "Error al iniciar sesión, intente nuevamente en unos minutos") return } self.signUpButton.animateButton(shouldLoad: false, withMessage: "") self.createUser(user.uid) // <----- user id from Firebase Auth self.presentClientStoryboard() } } and private func createUser(userId: String) { guard let nameAndLastname = nameAndLastnameTextField.text , let email = emailTextField.text , let password = passwordTextField.text , !nameAndLastname.isEmpty , !email.isEmpty , !password.isEmpty else { simpleAlert(title: "Error", msg: "Debe completar todos los campos") return } let newUserReference = Firestore.firestore().collection("users").document(userId) // <-- create a document, with the user id from Firebase Auth newUserReference.setData([ "nameAndLastname": nameAndLastname, "email": email, "password": password, "isAdmin": false, "timestamp": Timestamp() ]) }

Related questions

0 votes
    this is my first question here, i hope you can help me. I've been trying to get a specific path ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Right now my firebase cloud firestore looks like this: const db = fire.firestore(); db.collection(" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm relatively new to Swift and Firebase, so I'm not very familiar with the intricacies of how ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    I'm querying a collection for a specific document and trying to get the document-ID from the result of ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I know that the name of the user account can be retrieved from the built in variable User!UserID but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    How to change Swift version from 5 to 4 in Xcode?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    I am writing my first iOS application (iPhone only) with Swift. The main application view should allow user ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I tried to find out how to use firestore local emulator for python and for testing purpose. But I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I'm currently using Cloud Firestore as my backend for a mobile app. I've got basic payments working ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    In my application when the current logged in user's usernam is changed i want to update the UserDetails ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I have implemented Spring Security in my application. I have used default implementation, i.e., I have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have this operation EventModel data = EventModel(_nameEvent, _passEvent, _localEvent, _dateEventString); HashMap ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    In Firestore documentation said: There are no additional costs for using cursors, page tokens, and limits. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    In Firestore documentation said: There are no additional costs for using cursors, page tokens, and limits. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    A lossless line having 50 ohm characteristic impedance and length wavelength/4 is short circuited at ... by,electromagnetic theory engineering physics,electromagnetic theory nptel...
asked Nov 5, 2021 in Education by JackTerrance
...