Hi i need to append sessiontoken for services request after login, for successfull login i am using this.props.history.replace('/cards') and it is redirecting to cards page but initially sessiontoken is not adding to header, once i refresh the page sessiotoken is adding to request header: in index.js i am using axios interceptor:
const sessionToken = localStorage.getItem("sessionToken");
axios.interceptors.request.use(
request => {
console.log("inside index.js");
if (sessionToken) {
request.headers.sessionToken = sessionToken;
}
return request;
},
error => {
console.log(error);
return Promise.reject(error);
}
);
and in cards file:
const res = await axios.get(
"url"
);
in login
localStorage.setItem('accountInfo',JSON.stringify(response.data.account));
localStorage.setItem('sessionToken',response.data.sessionToken);
//this.props.history.replace('/cards')
this.props.history.push('/cards');
i have tried both history.push and history.replace both Where is the problem any help.