Kavin Kumar Arumugam
Kavin Kumar Arumugam

Reputation: 1832

iOS Swift Create Child in Firebase Realtime Database Programatically

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?

Upvotes: 1

Views: 1537

Answers (1)

kbunarjo
kbunarjo

Reputation: 1375

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.

Upvotes: 3

Related Questions