Here I am again. I'm trying to do a fetch to ask the API for a refreshed token based on previous stored token in localStorage. It gives error 400() and I still don't know why. It is required for the previous token to go on the body of the POST request.
Any help is acceptable, I feel really lost... I've been with this issue for days already...
fetch(url + '/api-token-refresh/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}, body: JSON.stringify({
token: localStorage.getItem('token')
})
})
I think the problem comes from when I store in localStorage, because on the Request Payload I get
token: "{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo0LCJ1c2VybmFtZSI6InJpY2FyZG8uY2Fycm9sYUBnbWFpbC5jb20iLCJleHAiOjE1MzMxMTY2OTQsImVtYWlsIjoicmljYXJkby5jYXJyb2xhQGdtYWlsLmNvbSIsIm9yaWdfaWF0IjoxNTMyNTExODk0fQ.sS3kuC8o51Rix505BFy9nT5w9iygNaKViGq_fVtVChk"}"
Qhat means I don't get just the token...
If you need anything else, just ask and I will add to the question.
console.log(localStorage.getItem('token'))return the expected result?console.log(localStorage.getItem('token'))then you probably just need to replacebody: JSON.stringify({ token: localStorage.getItem('token') })withbody: JSON.stringify(localStorage.getItem('token')), since localStorage returns already a key/value pair you don't need to recreate the body