• 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) => {

Viewing 1 replies (of 1 total)
  • I stumbled across the same problem when testing with Postman. Obvious in retrospect, but you must set your content type to ‘application/json’. Easy to overlook!

Viewing 1 replies (of 1 total)

The topic ‘[jwt_auth] empty_username’ is closed to new replies.