Skip to content
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

[2.x] Skip interceptor on specific endpoints #41

Closed
antonkomarev opened this issue Nov 23, 2019 · 6 comments
Closed

[2.x] Skip interceptor on specific endpoints #41

antonkomarev opened this issue Nov 23, 2019 · 6 comments

Comments

@antonkomarev
Copy link
Contributor

antonkomarev commented Nov 23, 2019

I faced the situation that on failed login action server respond with 401 error additional information error: "invalid_credentials" but interceptor started to refresh token because it treats all 401 errors as expired token. It will be good to have mechanism to exclude interception of the specific endpoints.

I've thought about this syntax:

createAuthRefreshInterceptor(axios, refreshAccessToken, {
    excludeEndpoints: {
       '/login' : {'post'},
    }
});

This implementation will have issues with ignoring endpoints like PATCH /products/104 because it will require to add wildcards support and it will bring too much complexity to the package.

@Flyrell
Copy link
Owner

Flyrell commented Nov 28, 2019

There's an option to skip interceptor for specific calls, isn't it an option for you? It's in beta now, but after your great work with contributions I guess you're already working on a beta.

EDIT: I saw your comment in previous issue, that it breaks SRP, but well... the package strongly depends on axios and right now there's no other option I have in mind. Also, I don't think endpoint matching is a good thing as it can create multiple bugs in one's configuration which wouldn't be obvious then. I don't want people to hate this package because of those "global" settings no one really knows about except the developer who wrote it.

@antonkomarev
Copy link
Contributor Author

antonkomarev commented Nov 28, 2019

Ah, sorry, I've missed this new feature. It should be enough:

export const postLogout = () => (
    httpClient.post('/logout', {}, {
        skipAuthRefresh: true,
    })
);

That solution is even better! Thank you for the handy script!

@antonkomarev
Copy link
Contributor Author

antonkomarev commented Nov 28, 2019

Reopened issue because I found that error.config.skipAuthRefresh is undefined in interceptor. Trying to debug and understand why is this happening.

@Flyrell
Copy link
Owner

Flyrell commented Nov 28, 2019

@antonkomarev aren't you using axios@0.19? Axios team changed behavior of custom properties in 0.19 and we're waiting for the fix. See axios#2295

@antonkomarev
Copy link
Contributor Author

Yes. Axios 0.19 :(

@antonkomarev
Copy link
Contributor Author

I've installed 0.18.1 and it's working well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants