title: Logout if token is expired
body: <p>I'm working on a react application that consists of many API requests. The structure of the application is</p>
  
  <p>When logging in, I'm receiving a token on response and I'm saving the token in my local storage to be used in other API requests.</p>
  
  <p>This token is expired every 30 minutes and if I do an API request after 30 minutes, I'm receiving a status of 401 in my request. I'm using this 401 status to do my logging out and clearing token data in local storage.</p>
  
  <p><strong>Example request</strong></p>
  
  <pre><code>export function stationDailyUsage(data) {
      return dispatch =&gt; {
          dispatch(dailyUsageLoading());
          axios.get(`${API_URL}/Dashboard/DailyUsage?type=${data.type}&amp;date=${data.date}`, {
              headers: {
                  'Authorization': `Bearer ${token}`
              },
          })
              .then(res =&gt; {
                  if (res.data.success === true) {
                      dispatch(dailyUsageSuccess(res.data));
                  } else {
                      console.log("error");
                  }
              })
              .catch(function (error) {
                  if(error.response.status === 401){
                      dispatch(logout());
                  }
                });
      }
  }
  </code></pre>
  
  <p>So to logout this way I have to do this check for every API I use (Around 40 APIs ). Is this the best approach to follow or is there a better way to handle the logout. I've read about <code>axios interceptors</code> but was not clear about how to implement it in my system. Any help is greatly appreciated.</p>