[jwt_auth] empty_username
-
I tried to post to ‘/wp/wp-json/jwt-auth/v1/token’ with axios,
But it seems that the username isnt coming trough, or at least in the headers I see there are slashes added
{\”username\”:\”email@email.com\”,\”password\”:\”Supersecretpassword\”}
In postman it works, the example gives me and encoded string
var data = “password=Supersecretpassword&username=email@email.com”;When i encode my object before sending it to axios it works!
var str = Object.keys(requestBody).map(function (key) {
return encodeURIComponent(key) + ‘=’ + encodeURIComponent(requestBody[key])
}).join(‘&’);So if anyone has the same problem, below works
const requestBody = {
“username”: formdata.email,
“password”:formdata.password
}const config = {
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded’
},
withCredentials: false
}//otherwise the ‘username’ is incorrect,
var str = Object.keys(requestBody).map(function (key) {
return encodeURIComponent(key) + ‘=’ + encodeURIComponent(requestBody[key])
}).join(‘&’);axios.post(url, requestBody, config)
.then((result) => {
The topic ‘[jwt_auth] empty_username’ is closed to new replies.