I have a Rest spring-boot API which, when a user authenticates the api returns the token jwt, I noticed in the browser that the token appears in the Response Header > Authentication and in the tests with the Postman it shows in the Body.
How can I get this token to store in the browser's Local Storage by Reactjs?
My code that makes the requests looks like this:
import { ACCESS_TOKEN, API_BASE_URL } from '../constants';
export function request (options) {
const headers = {
'Content-Type': 'application/json',
}
if(localStorage.getItem(ACCESS_TOKEN)) {
headers.append('Authorzation', 'Bearer ' + localStorage.getItem(ACCESS_TOKEN))
}
return fetch(API_BASE_URL+options.url, {
method: options.method,
headers: headers,
body: options.body
})
.then(function(response){
// Falta pegar o token e gravar na local estorage
if(!response.ok) {
return Promise.reject(json);
}
return json;
});
};