⛄Snowberb⛄ – 07-57 Feb 9

Having an interceptor do redirect to the login page when a certain status is seen, how could I do to not run the code for each of the api calls? auth.onLogout() gets called for each one of the responses that get 401
window.fetch = async (...args) => {
const [resource, config] = args;
const response = await originalFetch(resource, config);

if (response.status === 401) {
auth.onLogout(true);
setAlertState({ title: 'La sesión ha expirado', type: 'alert' });
}

return response;
};
window.fetch = async (...args) => {
const [resource, config] = args;
const response = await originalFetch(resource, config);

if (response.status === 401) {
auth.onLogout(true);
setAlertState({ title: 'La sesión ha expirado', type: 'alert' });
}

return response;
};
UU
Unknown User434d ago
S
Sniberb434d ago
I cant do that. I have to listen for a 401 I ended up using localstorage
UU
Unknown User433d ago