I have an axios interceptor that checks for 403 responses in case the user is not authenticated. What I'm looking for is to change the state of the user in context API from within the interceptor if the 403 response was found. The problem however is that I can't access context outside of the provider. Is there any way to change the state of the user in context when the interceptor catches a 403 response?
I was able to solve the problem by including the interceptor in a useEffect
in my Context component. This way, the interceptor is created once at the very top level of my app. Moreover, I can now change the state of my context from within the interceptor since it's now inside my Context component.