SniberbS
Reactiflux4y ago
6 replies
Sniberb

⛄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;
  };
Was this page helpful?