ios - Firebase: linking user UID to database -


i'm trying use current users uid unique identifier store associated user data there user uid in realtime database i.e. ref.child("user/uid"):

example: when user creates account added authentication section of firebase console , lets user fills in form i.e first name, last name, dob etc. how link data user uid in realtime database.

when register new user need first register code:

 firauth.auth()?.createuserwithemail(useremail, password: userpassword, completion: { (user, error) in 

on success response can set user more details use dictionary , use setvalue method adding child using following code:

ref.child("users").child(user!.uid).setvalue(["provider": self.txtpassword.text!,"email": self.txtemail.text!,"firstname": self.txtfname.text!,"lastname": self.txtlname.text!,"phone": self.txtphone.text!,]) 

here user!.uid unique user id child in main user tree.

so firebase tree :

enter image description here

and

enter image description here

sample code:

    @ibaction func actionregister(sender: uibutton) {                  let ref : firdatabasereference!                 ref = firdatabase.database().reference()                 firauth.auth()?.createuserwithemail("abc@abc.com", password: "1234567", completion: { (user, error) in                     if((error) != nil)                     {                         print("error = \(error?.localizeddescription)")                     }                     else                     {            // following method add user's  more details           ref.child("users").child(user!.uid).setvalue(["provider": "1234566", "email": "abc@abc.com", "firstname": "nitin", "lastname": "gohel", "phone": "12345678" ])           //following method registers user details           ref.child("users").child(user!.uid).observesingleeventoftype(.value, withblock: { snapshot in                             let postdict = snapshot.value as! [string : anyobject]                             print("error = \(postdict)")                         })                         }                 })              } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -