adding CSRF TOKEN in axios request

Viewed 3342

how can I set CSRF TOKEN in my axios request, I've tried this

// axios.defaults.xsrfCookieName = 'csrftoken';
// axios.defaults.xsrfHeaderName = 'X-XSRF-TOKEN';
const tokenApp = window.localStorage.getItem('token')

const { data: res } = await axios.post(`${URL}`, formData, {  
  withCredentials: true, 
  xsrfHeaderName: 'X-XSRF-TOKEN',
  headers: {
    Authorization: `${tokenApp}`,
    "Content-Type": "multipart/form-data"
  }
});

res.file = `http://20.88.238.192/azure-storage/api/blob/download/?file=${res.nameFile}`;
return res;

but i'm still getting 403 error (forbidden). Do I have to include something else?

1 Answers

Authorization: ${tokenApp}

probably needs to be:

Authorization: Bearer ${tokenApp}

But without details on your server side, what framework you are using, and some information about how the authentication is actually setup on the server side, there's no way, apart from guessing, to determine what is wrong.

Related