我如何创建一个用户的信息显示名称,用户名&用户照片? [英] How can i create a user with info about Display Name, username & Profile pic?
问题描述
我如何创建一个用户显示名称,用户名和密码?我可以用这个代码吗?
如果让user = FIRAuth.auth()?。currentUser
let name = user.displayName
let email = user.email
let photoUrl = user.photoURL
let uid = user.uid ; // Firebase项目所特有的用户ID。
//不要使用这个值来验证
//你的后端服务器,如果你有的话。使用
// getTokenWithCompletion:completion:改为。
} else {
//没有用户登录。
}
如果没有,为什么这个代码被使用?
哪些代码可以用来确定用户名,个人资料图片等?
我是firebase的新手。
< Firebase为使用FIRAuth Clases / API的用户提供认证
然而,它们不能被编辑自定义字段,如 Firebase数据库。
要允许用户自定义字段,您需要使用相同的唯一 uid
您在用户的身份验证中收到。像这样的东西
if let user = FIRAuth.auth()?currentUser {
pre>
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) - >无效
//现在用户存在于数据库中
})
}
我们把它放在我们的数据库的
users
终点处,并用uid
键由以下行/ users / \(key)
。How can i create a user with info about Display Name, username & Profile pic?
Can I use this code?
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. }
If not, for what purpose this code is used? And which code can be used to determine username, profile pic etc,?
I'm new to firebase.
解决方案Firebase provides authentication for users using the FIRAuth Clases/API
However they can't be edited with custom fields like the Firebase Database.
To allow custom fields for user, you need to duplicate users in the Database with the same unique
uid
you receive in the auth of the user. Something like thisif 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 }) }
We push it at the
users
end point in our db and with theuid
key by the following line/users/\(key)
.这篇关于我如何创建一个用户的信息显示名称,用户名&用户照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!