svrcekmichal / redux-axios-middleware

Redux middleware for fetching data with axios HTTP client
MIT License
918 stars 96 forks source link

OAuth2 Implementation #34

Closed llopez95 closed 7 years ago

llopez95 commented 7 years ago

Hi,

I was wondering how I could easily setup an interceptor that adds to requests headers an Authorization token excepted for some (like the one used to retrieve the token, etc..).

I'm asking you this since I couldn't find any way that allows the request intereceptor to get the proper action.

interceptors : {
      request: [({ getState, dispatch, action }, config) => {

No matter what action is performed, only the first one called will persist here (in my case the AUTH action if i'm not already signed in).

I've read on different issue that this is related to the client instance, but honestly I'm totally lost now and I can't figure out what to do.

I'd really appreciate some help! Thank for your great work too!

Regards,

svrcekmichal commented 7 years ago

Hi @llopez95 the described the issue you are mentioning here https://github.com/svrcekmichal/redux-axios-middleware/issues/33#issuecomment-247780722

For now I came up with only one solution, we will change it little bit and instead of action we will have getAction function which will return action which triggered interceptors. what do you think, @nmaves ?

llopez95 commented 7 years ago

@svrcekmichal, Thanks a lot for your fast answer. I was mostly worring that I was misusing the middleware and/or axios!

So if I got it, I'm not doing anything wrong. This is just a limitation of the middleware?

Let me know if I can help in anyway. Would be nice if we could include a simple OAuth2 implementation into redux-axios-middleware as it is nowadays largely used!

Regards,

svrcekmichal commented 7 years ago

Hi, I've made change, but I've found that mocked axios adapter does not trigger interceptors and I don't have any project I can test on now. I'm also little bit busy till monday. If you want you can try and install npm i -S svrcekmichal/redux-axios-middleware#feature/interceptor-get-action

In interceptor you can use getAction function which will return action. Hope it will helps, I'll test that on monday and publish it to NPM if working

svrcekmichal commented 7 years ago

I've created PR #35 . Please, @llopez95 try the branch above i send you. If it works(I tried it and it workd for me) we will release new version 3.1 with this change

llopez95 commented 7 years ago

Hi Michal,

Sorry I didn't have time to test it yet. I'll let you know as soon as I did. Thanks again for your reactivity! Much appreciated! :+1:

nmaves commented 7 years ago

@llopez95 have you had a chance to confirm the fix on #35 worked for you?

nmaves commented 7 years ago

Okay, I updated the feature branch and I removed the injected action so I think it is ready for a 4.0.0 release. We have lost the original requester but I think this should work. Thoughts @svrcekmichal ?

nmaves commented 7 years ago

The has been completed in the 4.0.0 release. We have removed the action parameter in favor of the newly added getSourceAction().