0

I'm trying to update a react redux node with jwt auth setup and trying to figure out why this code for password reset functionality:

/**
 * Reset password
 */
export function resetPassword(props) {
  return function (dispatch) {
    axios.post(`${API_URL}/reset-password`, props)
      .then(() => {
        dispatch({ type: RESET_PASSWORD_SUCCESS });

        history.push(`/reduxauth/reset-password/verify?email=${props.email}`);
        // browserHistory.push(`/reduxauth/reset-password/verify?email=${props.email}`); default
      })
      .catch(response => {
        dispatch(authError(RESET_PASSWORD_FAILURE, response.data.error))
      });
  }
}

keeps giving me this error: Uncaught (in promise) TypeError: Cannot read property 'error' of undefined

its referring to response.data.error in .catch above

I can't figure out why data is undefined?

user3125823
  • 1,846
  • 2
  • 18
  • 46
  • Please share the output of `console.log(response)` inside that `catch()`. What you are naming as `response` in the argument of the `catch()` may be the error itself and has no `data` property. – Alexander Staroselsky Jan 31 '19 at 22:04
  • What do you expect `response` to be? Do you know how `axios` rejects promises? – Felix Kling Jan 31 '19 at 22:06
  • Shouldn't it be `.then((response) => {..}` ? – stever Jan 31 '19 at 22:14
  • 1
    @stever: Parenthesis are optional if there is only one parameter. – Felix Kling Jan 31 '19 at 22:34
  • @AlexanderStaroselsky - the console.log(response) - says that the history.push line is not a function... I thought I replaced browserHistory.push correctly. Any ideas how to correct the history.push line? I updated this from RR v2 to RR v4 with no problems until now.... ? – user3125823 Jan 31 '19 at 22:35
  • Okay, so hopefully that clarifies why the error `uncaught (in promise) TypeError: Cannot read property 'error' of undefined` was happening when you were trying to evaluate `response.error.data`. In terms of the actual error regarding `history`, you will need to provide code regarding how exactly `history` is provided to this function/component/file/etc. You should also update the question with output of this `console.log(response)` statement. – Alexander Staroselsky Jan 31 '19 at 22:37
  • You may simply need to restructure how/when you `history.push()`. If you are using `redux-thunk` you can `this.props.history.push()` from the component that dispatched this action instead. Either way, the real issue is `history.push()` as you migrated to a different version of react router. – Alexander Staroselsky Jan 31 '19 at 22:48
  • @AlexanderStaroselsky - I didn't intend it to be a duplicate but it did end up being a duplicate - in any case - that answer definitely helped - no more error! TY. – user3125823 Jan 31 '19 at 23:27

0 Answers0