isotoma / react-cognito

Library for integrating Facebook React and Amazon Cognito
Apache License 2.0
116 stars 48 forks source link

BUG - performLogin called multiple times #35

Open andrepcg opened 6 years ago

andrepcg commented 6 years ago

If you dispatch multiple actions when cognito.state is LOGGING_IN, performLogin is going to be called a number of times equal to the number of actions dispatched.

This happens because the enable function is subscribed to the store and it runs every time an action is dispatched. The, identityPoolLogin is going to be called multiple times and the validation state.cognito.state === CognitoState.LOGGING_IN can be true for a few milliseconds, thus performing login multiple times

orther commented 6 years ago

I noticed this bug too but I hadn't tracked down the cause. After reviewing policy.js it looks like you're correct. An easy solution would be to use observerStore (described here https://github.com/reactjs/redux/issues/303#issuecomment-125184409) to only call the listeners when state.cognito.state changes/transitions.