Jasham
Jasham

Reputation: 321

How to send axios put request with jwt token in reactjs

I have tried to put details to server but getting 403 error

below is my code.

export const updateAppTypeData = (appData) => async dispatch => {
  const token = localStorage.getItem('token')
  const response = await axios({
    method : 'put',
    url: ('http://localhost:8000/api/posts/appType/'+appData.id+'/'),
    data: appData,
    headers: {'Content-Type': 'application/json', 'Authorization': 'Token '+token},
    json: true
  }).then(function (response) {
        console.log(response);
  });
  //dispatch({ type : FETCH_APP_TYPE , payload: response.data });
};

Any help will be a big plus. Thanks.

Upvotes: 1

Views: 1573

Answers (1)

Maielo
Maielo

Reputation: 732

I think you are missing "Bearer" keyword in your header which is one of the allowed types (others are like like basic or digest). Per RFC6750 and RFC6749

...
headers: {'Content-Type': 'application/json', 'Authorization': 'Bearer '+token}
...

Upvotes: 2

Related Questions