I have this piece of code located inside of the index.js file.
The situation here is that when there is an error code of 403, I want it so the user token is removed and then the login component is automatically rendered.
The problem is that index.js does not have access to this.props.history and hence can't use it, what is another way of redirecting to the login page?
axios.interceptors.response.use(res => {
console.log(res);
return res;
}, err => {
console.log(err.response);
if (err.response.status === 403) {
AuthHelper.removeUserToken();
// Go back to login page by this.props.history.push('/login');
}
return Promise.reject(err);
})