1
I have a spring-boot Rest API which, when a user authenticates the api returns the jwt token, I noticed in the browser that the token appears in Response Header > Authentication and in tests with Postman it shows in Body.
How can I get this token to store in the browser’s Local Storage by Reactjs ?
My code that makes the requisitions is 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;
});
};