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

Axios auth refresh doesn't work with axios v1.1.3 #219

Open
SuryaNelakanti opened this issue Oct 21, 2022 · 7 comments
Open

Axios auth refresh doesn't work with axios v1.1.3 #219

SuryaNelakanti opened this issue Oct 21, 2022 · 7 comments

Comments

@SuryaNelakanti
Copy link

SuryaNelakanti commented Oct 21, 2022

Whenever i run a build it gives this Writable is not defined error.

I have downgraded axios to version 1.1.2 and it works fine.

@shurco
Copy link

shurco commented Oct 25, 2022

I stopped working even on version 1.0.0

@3tw
Copy link

3tw commented Oct 26, 2022

Whenever i run a build it gives this Writable is not defined error.

Perhaps you re missing 'stream' module inside your build

// node-modules/follow-redirects/index.js`
var Writable = require("stream").Writable;`

Are you using Vite or Webpack?

@brenjt
Copy link

brenjt commented Dec 15, 2022

I have this same problem using Vite

@aichichang
Copy link

Had the same issue, upgrade to axios 1.2.2 fixed it.

The refresh logic function was called when hitting a 401 but the response.config.headers.Authorization bearer token is not attached to the API call correctly. I got [Object object]: undefined and so the call failed again with 403...
Screenshot 2022-12-30 at 16 09 58

@alex-moiseenko
Copy link

i have the same problem when using Vite.

image

I've spent several hours looking for a solution, this problem is related to node modules. In my case it was 'url' and 'stream' modules.

I'm found this plugin https://github.com/voracious/vite-plugin-node-polyfills and it fixed problem.

@prateekinfi
Copy link

prateekinfi commented Jan 11, 2023

@aichichang

I think i know the cause of your issue specifically. There is a problem here:

return instance(error.response.config);

In the older Axios versions, error.response.config and error.response.config.headers used to be a plain objects but the later versions have seemed to changed something.

The class of error is now AxiosError and the class of error.response.config.headers is AxiosHeaders. These are directly being passed back to the axios instance without sanitising the input config. I don't think Axios is able to correctly parse such objects and that's why you see '[Object object]' in your header.

It is debatable whether this could be considered a problem with axios or axios-auth-refresh.

@prateekinfi
Copy link

Did anyone figure out a way to work around the problem I mentioned above?
@aichichang did the solution mentioned by @alex-moiseenko work for you?

My security team needs me to upgrade axios and I can't delay it anymore. Just realized it's exactly one year since my comment 😄 . Didn't expect this thread to be this quiet 🤪

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

7 participants