title: Adding the displayName whilst using createUserWithEmailAndPassword
body: <p>I want to add the display name to the user that was just created. But when I createUserWithEmailAndPassword it sais my currentUser is null. Anything wrong?</p>
  
  <pre><code>var name = document.getElementById("name").value;
  var username = document.getElementById("username").value;
  var email = document.getElementById('email').value;
  var password = document.getElementById('password').value;
    // Sign in with email and pass.
    // [START createwithemail]
    firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      // [START_EXCLUDE]
      if (errorCode == 'auth/weak-password') {
        alert('The password is too weak.');
      } else {
        console.error(error);
      }
      // [END_EXCLUDE]
    });
    // [END createwithemail]
    var user = firebase.auth().currentUser;
    user.updateProfile({
        displayName: username
      }).then(function() {
        // Update successful.
      }, function(error) {
        // An error happened.
    });
  document.getElementById("submitButton").innerHTML = "Loading...";
  $("#submitButton").css("background-color", "#efefef");
  $("#submitButton").css("cursor", "init");
  $("#submitButton").css("color", "#aaa");
  registerUserToDB(username, name, email);
  console.log("shouldhave worked");
  </code></pre>