我正在尝试使用当前用户uid作为唯一标识符,以将相关的用户数据存储为实时数据库中的用户uid,即ref.child(“ User / uid”):
示例:当用户创建一个帐户时,将其添加到Firebase控制台的身份验证部分,并说用户填写了一个表格,例如名字,姓氏,DOB等。我如何将数据实时链接到用户UID数据库。
当您注册任何新用户时,您需要先注册代码:
FIRAuth.auth()?.createUserWithEmail(UserEmail, password: UserPassword, completion: { (user, error) in
在成功响应上,可以通过使用以下代码添加Child来设置用户更多详细信息的使用dictionary
和使用SetValue
方法:
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!,])
这里的user!.uid是您的主USER树中唯一的用户ID子级。
所以你的firebase树看起来像:
和
样例代码:
@IBAction func ActionRegister(sender: UIButton) {
let ref : FIRDatabaseReference!
ref = FIRDatabase.database().reference()
FIRAuth.auth()?.createUserWithEmail("[email protected]", password: "1234567", completion: { (user, error) in
if((error) != nil)
{
print("Error is = \(error?.localizedDescription)")
}
else
{
// following method is a add user's more details
ref.child("users").child(user!.uid).setValue(["Provider": "1234566", "Email": "[email protected]", "Firstname": "nitin", "Lastname": "Gohel", "Phone": "12345678" ])
//following method get the registers user details
ref.child("users").child(user!.uid).observeSingleEventOfType(.Value, withBlock: { snapshot in
let postDict = snapshot.value as! [String : AnyObject]
print("Error is = \(postDict)")
})
}
})
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句