I have an axios interceptors and when a user gets forced logged out(because of expired token) I want to go back to my home page.
I am not sure how to pass react router to it though. I am using mobx but not sure if that will help me with this problem.
export const axiosInstance = axios.create({
baseURL: 'https://localhost:44391/api',
timeout: 5000,
contentType: "application/json",
Authorization: getAuthToken()
})
axiosInstance.interceptors.response.use(function (response) {
return response;
}, function (error) {
const originalRequest = error.config;
if(error.code != "ECONNABORTED" && error.response.status === 401 && !originalRequest._retry){
originalRequest._retry = true;
return axiosInstance.post("/tokens/auth",{
"refreshToken": getRefreshToken(),
"grantType": "refresh_token"
}).then(response => {
localStorage.authentication = JSON.stringify(response.data);
updateAuthInstant();
return axiosInstance(originalRequest)
});
}
return Promise.reject(error);
});