react-redux-jwt-auth-example icon indicating copy to clipboard operation
react-redux-jwt-auth-example copied to clipboard

Why do you call a payload data a token?

Open wzup opened this issue 8 years ago • 1 comments

Here is an operation from https://github.com/joshgeller/react-redux-jwt-auth-example/blob/master/src/actions/index.js#L63.

In decoded varibale in not a token. It is only a payload object which is only one third of a token.

let decoded = jwtDecode(response.token); // decoded in not a token. It is a payload object only!
dispatch(loginUserSuccess(response.token));

And in loginUserSuccess action you have:

export function loginUserSuccess(token) {
  localStorage.setItem('token', token); // why token? It is not a token, it is a payload object
  return {
    type: LOGIN_USER_SUCCESS,
    payload: {
      token: token
    }
  }
}

Why do you call a payload data a token?

wzup avatar Oct 06 '16 21:10 wzup

No idea if I am right or not, but the response is the JSON value returned from the server.. In this case, { token: '3fj39jf9j3f' }

I'm not sure why he has the jwtDecode line in there, as he never ends up using decoded. Thus it is actually the token, and also you can really pass in any object key into the action object. I'm guessing payload is just a common word for the 'data' embedded in an action.

Andrew1431 avatar Feb 08 '17 23:02 Andrew1431