Sniberb
Sniberb2y ago

⛄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;
};
4 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Sniberb
SniberbOP2y ago
I cant do that. I have to listen for a 401 I ended up using localstorage
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
reactibot
reactibot2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1073150620657262673

Did you find this page helpful?