-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] how to change state in responseHandler? #146
Comments
I think there is an example of exactly what you're trying to do here: https://github.com/lexich/redux-api/blob/master/docs/AuthorizationJWT.md |
@divan if you use solutions like redux-router postfetch option can help you for concrete endpoint. reduxApi({ ... }).use("responseHandler",
(err, data)=> {
if (isNeedRedirect(err)) {
store.dispatch(redirectTo(''));
// or
window.location.href = '.....';
// or you router api
}
}); But you should be careful, because this method catch all requests, and not at all bad responses need to been redirected. |
@jakeaaron thanks, I've checked this example, but it's not clear. What is If I understood it correctly, I think my approach is slightly different - if any of normal API requests is getting "Unuathorized" error from backend, simply dispatch logout action (which will handle token local storage and router redirection). @lexich is it a right way to do redirect using And, to be clear, I'm not trying to invent anything on my own. I'm trying to go as "standard" as possible. And I suppose, this functionality is a very basic one. |
@divan it depends. If you use react-router, you should use it redirect methods |
Hi,
I'm trying to implement straightforward thing - catch "Unauthorized" error and redirect user to the "/login" page. How do I do that with redux-api?
I assume the way to go is to implement
responseHandler
but it's unclear how to access state from within it.Any suggestions? Thanks in advance.
The text was updated successfully, but these errors were encountered: