2

In the async fetch of the AUTH_LOGIN we want to dispatch an action after we fetch data from additional endpoints (apart from the login endpoint, for example we call another endpoint to bring data for the account, etc.).

We have all in place (action, reducer, used the combineReducers, etc.), but we are not sure how we can "connect" the authClient function in the authClient.js file, as this is not a component in order to use the connect function.

How could we dispatch an action then?

user2078023
  • 1,137
  • 1
  • 10
  • 28

1 Answers1

1

As you can see in the authentication side effect, the data returned by your authClient will be set as the payload of the USER_LOGIN_SUCCESS action which will be dispatched automatically when the authClient resolve.

To apply any logic to the authentication payloa and eventually dispatch some custom actions, you'll have to create a custom saga which will react to USER_LOGIN_SUCCESS actions.

We should definitely add an example in the documentation

Gildas Garcia
  • 6,966
  • 3
  • 15
  • 29
  • Thanks! Indeed, if you could add an examplein the documentation that would be great because the 'saga' concepts are new to many devs. – user2078023 Apr 25 '18 at 07:11
  • @Glidas, I succeeded based on your recommendations! Only one "culprit" is that I also have to do the same FETCH for "CHECK_USER", so that the app will fetch the necessary (extra) data even when a BROWSER REFRESH occurs. I have a "window.extraDataFetched" flag that I got the data, but while this does work it does fetch 3 times in the beginning. Any ideas how to disallow this? – user2078023 Apr 25 '18 at 15:20
  • Actually, I used `takeLatest(USER_CHECK, fetchExtraLoginData)` instead and seems to be working, except that it fetches 2 times, not just 1. – user2078023 Apr 25 '18 at 15:28