createUser = (
  dispatch,
  firebase,
  { email, password },
  profile
) => {
  dispatchLoginError(dispatch, null)

  if (!email || !password) {
    const error = new Error('Email and Password are required to create user')
    dispatchLoginError(dispatch, error)
    return Promise.reject(error)
  }

  return firebase
    .auth()
    .createUserWithEmailAndPassword(email, password)
    .then((userData) =>
      // Login to newly created account flag is not set to false
      createUserProfile(dispatch, firebase, userData, profile || { email })
    )
    .catch((err) => {
      dispatchLoginError(dispatch, err)
      return Promise.reject(err)
    })
}
Create a new user in auth and add an account to userProfile root
@param {Function} dispatch - Action dispatch function
@param {object} firebase - Internal firebase object
@param {object} credentials - Login credentials
@param {string} credentials.email - Email of user
@param {string} credentials.password - Password of new user
@param {object} profile - Profile to store in database for new user
@returns {Promise} Resolves after user is created
@private