specific-silverS
Refine3y ago
25 replies
specific-silver

authProvider onError Only Called on Final Error

Hi!

I have an authentication token for my API that expires after a certain amount of time.

Once it does, the application receives an error when it tries to fetch data (as expected).

I have authProvider's onError set up so that when it receives a 401, it logs the user out and redirects them to the login page.

onError: async (error) => {
    const status = error.statusCode;  
    if (status === 401) {  // expired token
      return {  
      logout: true,  
      redirectTo: "/login",  
      error: new Error(error)
      };  
    }  
    return { error }; 
  },


However, onError is only called after multiple failures.

I'm wondering if I can log the user out via an Axios interceptor rather than authProvider's onError?
image.png
Was this page helpful?