updateEmail = (dispatch, firebase, newEmail, updateInProfile) => {
  dispatch({ type: actionTypes.EMAIL_UPDATE_START, payload: newEmail })

  if (!firebase.auth().currentUser) {
    const error = new Error('User must be logged in to update email.')
    dispatch({ type: actionTypes.EMAIL_UPDATE_ERROR, error })
    return Promise.reject(error)
  }

  return firebase
    .auth()
    .currentUser.updateEmail(newEmail)
    .then((payload) => {
      dispatch({ type: actionTypes.EMAIL_UPDATE_SUCCESS, payload: newEmail })
      if (updateInProfile) {
        return updateProfile(dispatch, firebase, { email: newEmail })
      }
      return payload
    })
    .catch((error) => {
      dispatch({ type: actionTypes.EMAIL_UPDATE_ERROR, error })
      return Promise.reject(error)
    })
}
Update user's email within Firebase auth and optionally within
users's profile. Internally calls `firebase.auth().currentUser.updateEmail`.
@param {Function} dispatch - Action dispatch function
@param {object} firebase - Internal firebase object
@param {string} newEmail - Update to be auth object
@param {boolean} updateInProfile - Whether or not to update email within
user's profile object (stored under path provided to userProfile config)
@returns {Promise} Resolves with results of updating email
@private