2

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

14
  • does this have a value sessionStorage.getItem("token") and can you show how did you test in postman (may be a screenshot) ? Commented Aug 31, 2022 at 8:08
  • @KcH i have updted the question with screen shot Commented Aug 31, 2022 at 8:17
  • @KcH console.log(headers); i am getiing the token here Commented Aug 31, 2022 at 8:17
  • this is not helpful tbh, need a screen shot headers, where token gets passed Commented Aug 31, 2022 at 8:24
  • @KcH do u want screen shot of the browsers console.tab? Commented Aug 31, 2022 at 8:32

1 Answer 1

1

Try the headers as so :)

   axios
    .delete("your_url", {
      headers: headers,
      data: Data
    })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.