我有一个多线程拦截器,当用户被迫注销(因为过期令牌),我想回到我的主页。
但我不知道如何将react路由器传递给它。我正在使用mobx,但不确定这是否能帮助我解决这个问题。
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);
});