How do i make a post request with my token coming from local storage

Having problems getting this to work. although it works when tested with postman

export const addAdmin = (values) => async (dispatch) => {


var add = localStorage.getItem('user');

const res = await fetch('https://capitalluxurydev.xyz/v1/admin/createadmin', {
    method: 'POST',
    body: JSON.stringify(values),
    headers: {
        Authorization: add,
        'Content-Type': 'application/json; charset=utf-8',
    },
    credentials: 'same-origin',
});
try {
    const data = await res.json();
    console.log(data);

    return;
} catch (error) {
    console.log(error);

    return;
}

};

I keep getting a response of invalid JSON construct

    {data: null
error: "invalid json construct"
message: ""
statuscode: 422
}

But works perfectly on https://hoppscotch.io/

67 thoughts on “How do i make a post request with my token coming from local storage”

  1. 22564 517179You can undoubtedly see your skills within the work you write. The world hopes for a lot more passionate writers like you who arent afraid to say how they believe. At all times follow your heart 401249

    Reply

Leave a Comment