You can simply solve your problem as follows.
1) Create a user using the following statement.
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {});
2) The success of the above operator. authenticate this user as shown below.
self.rootRef.authUser(email, password)
3) The success of the above function sets the user with a username and profile picture as follows.
usersRef.updateChildValues(dict, withCompletionBlock:
-Register userRef with your userDetails / USER_ID
Perhaps you will work. I have code, but I work for an older version of firebase, so I do not work for you, otherwise I have a share with you.
source share