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

Bug with axios.create and baseURL option? #20

Closed
sustained opened this issue Jun 17, 2019 · 6 comments
Closed

Bug with axios.create and baseURL option? #20

sustained opened this issue Jun 17, 2019 · 6 comments

Comments

@sustained
Copy link

sustained commented Jun 17, 2019

First let me just say thanks for creating a great little library.

I think I've found a bug.

I set my JWT TTL to 60 seconds but the refresh TTL longer so that I can debug this JWT stuff and get it working.

So, I log into my application and then wait > 60 seconds, then I hit an authenticated route /api/auth/me and get a 401.

The interceptor kicks in and hits the refresh token route (/api/auth/refresh), which returns a new token and all that jazz.

After that, I see the original route that triggered the 401 getting hit again... except for one slight problem - It's hitting /api/api/auth/me. The api part is now doubled.

@Flyrell
Copy link
Owner

Flyrell commented Jun 17, 2019

Hi. Thanks for the issue.

Can you please share your code for the interceptor and other things associated with it (like the actual call, other interceptors, etc.) ?

@sustained
Copy link
Author

sustained commented Jun 17, 2019

I followed the docs exactly and don't have any other interceptors.

I removed the baseURL of /api from axios.create and prefixed all my axios calls with /api to see what happened and the problem went away, so I'm almost certain it's your library.

@Flyrell
Copy link
Owner

Flyrell commented Jun 17, 2019

Inside your refreshAuthLogic callback, just unset the baseURL. Unfortunately, this is a problem with axios (not sure if that's the problem or desired behavior). I can't find the source I know it from, but here's the actual implementation I did when I was explaining the library a bit. StackOverflow answer.

The thing is, url in axios' error config is the full url and the config still has the baseURL option set.

I didn't want to change this, as this should be "just an interceptor" and I don't want people to get confused. Please, let me know if that helped.

Thanks

@sustained
Copy link
Author

Hrm... that feels terrible hacky but it is a solution so I'll bear it in mind, thanks.

Think it's worth an issue on the axios tracker? I'm not really sure I know enough about either library to be the one to file it though.

Thanks for the responses!

@Flyrell
Copy link
Owner

Flyrell commented Jun 18, 2019

As I said earlier, I'm not sure if that's a bug or desired behavior. Either way, it feels like it shouldn't be like that, so it might be worth opening the issue and see what axios team has to say about it.

If you do so, please, refer to this issue, so anyone with the same problem can see the thread.

Thanks.

@Flyrell Flyrell closed this as completed Jun 18, 2019
@jacobmllr95
Copy link

Resetting the baseURL works for the initial failing request but queued requests have the same issue and there is currently no solution to adjust those.

IMHO there should be a global baseURL handling or a config option to define a callback for queued requests to be able transform their configs too.

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

3 participants