2
Hi, I’m creating a Interceptor to the Xios which, if my Answer case there is an error with the status Forbidden (403) the same need to trigger the Action that starts the user’s logoff to force him to re-use.
This is necessary because it triggers a series of cascading actions and is already configured for such a feature.
My problem is that I don’t know how to connect a function to Redux without having a React component. So far my Interceptor is this way:
import axios from 'axios'
import { logoffRequest } from 'store/actions/userActions'
axios.interceptors.response.use(
response => response,
error => {
if (403 === error.response.status) {
logoffRequest()
}
}
)
The action logoffRequest
depends on a Redux to work because it moves a lot of states of the application, including sending data to the backend...
What I need to do to make it possible to call this Action from within this Interceptor?
But if I do this, when I pull the store from a file I will ta calling again the creation of it and I will lose the information no?
– LeandroLuk
@Leandroluk I believe not, tested this code?
– Marconi
did not get to testing, I resolved encapsulating the declaration of interceptors within a function that receives the store itself.
– LeandroLuk