Axios delete not working in react js with Authorization token

Viewed 70

I am trying to run a delete query with react js. In Postman my delete query is working, but in my code it says no Authorization

I did

console.log(headers)

to check if header is available but still it's not working. I have posted what I have tried

const deletefile = (e) => {
    const headers = {
      Authorization: `Token ${sessionStorage.getItem("token")}`,
    };
    console.log(headers);
    const Data = {
      id: e,
      //   // stage: "stage9",
      //   notes: notes,
    };
    axios
      .delete("file/", Data, {
        headers: headers,
      })

      .then(() => {
        alert("success submited");
        // setRefresh(Refresh + 1);
      })
      .catch((error) => {
        alert(error);
      });

enter image description here

enter image description here

1 Answers

Try the headers as so :)

   axios
    .delete("your_url", {
      headers: headers,
      data: Data
    })
Related