如何创建一个包含显示名称,用户名和信息的用户?个人资料照片?
我可以使用此代码吗?
if let user = FIRAuth.auth()?.currentUser
let name = user.displayName
let email = user.email
let photoUrl = user.photoURL
let uid = user.uid; // The user's ID, unique to the Firebase project.
// Do NOT use this value to authenticate with
// your backend server, if you have one. Use
// getTokenWithCompletion:completion: instead.
} else {
// No user is signed in.
}
如果没有,为什么使用此代码? 哪些代码可用于确定用户名,个人资料图片等?
我是firebase的新手。
答案 0 :(得分:1)
Firebase使用FIRAuth Clases / API
为用户提供身份验证但是,无法使用 Firebase数据库等自定义字段对其进行编辑。
要允许用户使用自定义字段,您需要使用您在用户身份验证中收到的相同唯一uid
复制数据库中的用户。像这样的东西
if let user = FIRAuth.auth()?.currentUser {
let name = user.displayName
let email = user.email
let photoUrl = user.photoURL
let uid = user.uid;
let ref = FIRDatabase.database().reference()
let key = uid
let userDict = [ "name" : name ,
"email" : email,
"photoUrl" : photoUrl]
let childUpdates = ["/users/\(key)": userDict]
ref.updateChildValues(childUpdates, withCompletionBlock: { (error, ref) -> Void in
// now users exist in the database
})
}
我们在数据库的users
终点推送它,并使用uid
键推送到以下行/users/\(key)
。