New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
axios interceptors last request #1902
Comments
@michaelAkrawi any news? I tried to do the refresh token inside the interceptors response, however it goes into a loop =/ |
@marcelogarbin i don't have a loop problem with this solution |
I'm getting the similar problem: the dataType of error reponse is not an object like [README: Handling Errors] said. Instead, when I console it, it shows like:
How can I get the data from server response Update: #1923 |
Hello, my implementation is different but I can confirm it works. Call See #1676 for an approach that handles concurrent 401s as a result of concurrent requests with an expired token. export function setupAxios(axios) {
setJwtIfExists();
axios.interceptors.response.use(function(response) {
return response;
}, function(error) {
const originalRequest = error.config;
if (error.response.status === 401) {
originalRequest._retry = true;
return refreshJwt().then(({data}) => {
originalRequest.headers['Authorization'] = 'Bearer ' + String(data.token);
return axios(originalRequest);
}).catch((resp) => {
store.dispatch(logout(1)) //logout on failure to authenticate (e.g. expired refresh token)
return Promise.reject(resp)
});
}
return Promise.reject(error);
})
}
export function refreshJwt() {
const refreshToken = window.localStorage.getItem('refresh_token');
return axios.post('/tokens/refresh', {token: refreshToken}).then((resp) => {
window.sessionStorage.setItem('token', resp.data.token);
setJwtIfExists();
return resp
})
}
function setJwtIfExists() {
const token = window.sessionStorage.getItem('token');
if (token) {
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
} else {
axios.defaults.headers.common['Authorization'] = null;
}
} |
I have an issue where Has anyone else seen an issue like this? |
Closed due to nothing axios needs to do. Usually the problem is that users didn't connect promises well. @michaelAkrawi I think
|
I have my vue.js app & web api REST service using JWT authentication. the problem starts when i call some action on my api but i get 401 from it saying the token has been expired.
so i used axios interceptors to catch all this response on my app.vue component:
then when im trying to call the original request i made to the api (fetching/updating some data), the original request has been called but the response.data object is undefined for some reason.
for the example let's say this is the original call :
The text was updated successfully, but these errors were encountered: