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

Add ability to disable interceptor for specific calls #16

Closed
Flyrell opened this issue May 16, 2019 · 6 comments
Closed

Add ability to disable interceptor for specific calls #16

Flyrell opened this issue May 16, 2019 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@Flyrell
Copy link
Owner

Flyrell commented May 16, 2019

It would be nice to add the ability to disable interceptor for some of the requests. Right now this is only possible by using multiple instances of the axios. After a discussion with axios contributors we know it's possible to add your own properties to the requests' configuration which would enable us to do that.

@Flyrell Flyrell added this to the v1.1.0 milestone May 16, 2019
@Flyrell Flyrell added the enhancement New feature or request label May 16, 2019
@krixon
Copy link

krixon commented Aug 28, 2019

I am actually having an issue which I believe could be resolved with this.

My refresh logic itself issues a request using axios - it makes a POST request to exchange a refresh token for a new access token. However this request itself is queued so I the refresh logic promise never resolves.

Unless I am missing something? It seems this would be a pretty common issue but I don't see any reports of it.

@Flyrell
Copy link
Owner Author

Flyrell commented Aug 30, 2019

@krixon Wow, you surprised me... this should not be happening at all. Did you try it on the current master? Would you be able to reproduce and share the issue? Thanks.

@Flyrell
Copy link
Owner Author

Flyrell commented Sep 23, 2019

Fixed in #27. Please, give it a try before I publish it as latest release (it's in beta now).

npm install axios-auth-refresh@beta --save

@Flyrell Flyrell closed this as completed Sep 23, 2019
@LeoniePhiline
Copy link

LeoniePhiline commented Nov 16, 2019

Just to confirm, I also ran into this (what @krixon) described.
Going to try the beta now. @Flyrell The TS code looks like request queue interceptors are still added unconditionally, aren't they?

Maybe @krixon is using some Promise/async flow to retrieve the refresh token, before sending the refresh request...

I am using your interceptor to ask the user for a Authenticator one time password via a Quasar Dialog. If the dialog is submittted (not canceled), I try sending a request to laravel to verify the OTP, but the request is stuck in the request queue interceptor.

The code works for everyone else, because they synchronously send the refresh request before adding the request interceptors (only the response is asynchronous).
However, I need to wait for the user to enter their OTP and confirm the dialog, so I'll asynchronously fire my request right into the queue and nothing happens any more. Gotta reload. ;)

Probably I need to base my own interceptor on your wonderful work. Thank you in any case!
If you could add a request option to except said request from the queue, that would be grand.

Edit:
The solution I chose was using a separate axios instance for POSTing the Authenticator OTP to laravel. Feels dirty, though.

@krixon
Copy link

krixon commented Nov 16, 2019

Sorry for the late reply.

Probably I need to base my own interceptor on your wonderful work

This is what I did in the end as I had to move on quickly. I added the ability to provide a whitelist of endpoint uri patterns and avoided queueing matching requests, which is pretty simplistic but enough for my use case.

@Flyrell
Copy link
Owner Author

Flyrell commented Nov 16, 2019

@krixon in @beta version you should be able to just add skipAuthRefresh property to your request object and the interceptor won't be triggered at all. Give it a try if you have some time, I could use some beta testers for sure 😜

This should also work for you @LeoniePhiline if I understand your issue correctly, just add the property to the call that shouldn't be queued (well... it won't be intercepted at all if it's not a problem).

You can find more about it in Beta Readme.

PS: You might need to check the lockfile for the axios version as the the request object is messed up a little in v0.19 of axios and there's no fix yet. In case you use 0.19, please roll back to 0.18 for a while until they fix it. The problem is that in 0.19 they don't preserve the request object structure (they reset it), so the property skipAuthRefresh wouldn't be preserved. The issue to track is axios/#2295

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

No branches or pull requests

3 participants