How can i create a user with info about Display Name, username & Profile pic?

后端 未结 1 679
太阳男子
太阳男子 2021-01-16 16:22

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          


        
相关标签:
1条回答
  • 2021-01-16 16:44

    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 this

    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
            })
    } 
    

    We push it at the users end point in our db and with the uid key by the following line /users/\(key).

    0 讨论(0)
提交回复
热议问题