How can I send an authentication header with a token via axios.js?I have tried a few things without success, for example: . Gives me this error: . I have managed to get it work by setting global default, but I'm guessing this is not the best idea for a single request: .
Cole's answer helped me find the problem.
I am using django-cors-headers middleware which already handles authorization header by default. But I was able to understand the error message and fixed an error in my axios request code, which should look like this .
If any of the headers you want to send were not listed in either the spec's list of whitelisted headers or the server's preflight response, then the browser will refuse to send your request.
In your case, you're trying to send an Authorization header, which is not considered one of the universally safe to send headers.
The browser then sends a preflight request to ask the server whether it should send that header.