I have configured my app with Firebase. In my app I have user creation and login methods (using their email and password). I need to create new child in Firebase's Database when a new user is created. How can I do this?
Asked
Modified
5 years, 8 months ago
Viewed
2k times
Part
of Mobile Development and Google Cloud Collectives
1 Answer
After you do the FIRAuth.auth()?.createUser, you can check if the error is nil or not. If it is not, then you know the user has been created, and therefore can add your new child. You can do this by writing:
let uid: String = (FIRAuth.auth()?.currentUser?.uid)!
FIRDatabase.database().reference().child(uid).setValue(arrayOfData)
Therefore, the new node that you create is the user's Firebase ID, and will definitely be unique.
2 Comments
Kavin Kumar Arumugam
Ya its Working Thanks For Your Support.
Anton Bjerg
Thank you for this fix - even though I know it is a few years old! :D I am really struggling with then finding the path for a specific index in the array that I have then created! - When I then want my user to be able to edit e.g. his/her nationality, which may be at index 5 in the array created when signing up! Hope the questions makes sense. Thank you :-)