joshgeller / react-redux-jwt-auth-example

Sample project showing possible authentication flow using React, Redux, React-Router, and JWT
MIT License
1.58k stars 237 forks source link

Why do you call a payload data a token? #35

Open wzup opened 8 years ago

wzup commented 8 years ago

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?

Andrew1431 commented 7 years ago

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.