0π
β
The issue is resolved π
In fact, Djoser cannot accept the request of type application/json
. This can be verified by performing an OPTIONS request to /auth/token/create
endpoint. So we need to make a request in one of the supported formats:
"parses": [
"application/vnd.api+json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
I have chosen application/x-www-form-urlencoded
. So now the question was to send such a request with Axios:
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
var querystring = require('querystring');
setLogin() {
axios({
method: 'post',
url: 'auth/token/create/',
data:
querystring.stringify({username: this.login, password: this.password})
})
.then(response => (
localStorage.setItem("auth_token", response.data.data.attributes.auth_token)
))
.catch(error =>
alert(error)
)
}
Source:stackexchange.com