如何创建包含显示名称、用户名和个人资料图片信息的用户?



如何创建包含显示名称,用户名和个人资料图片信息的用户?

我可以使用此代码吗?

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 使用 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)

最新更新