Skip to content

Commit

Permalink
Merge pull request #3076 from inh556/addIsMounted
Browse files Browse the repository at this point in the history
added isMounted to check if the component has been unmounted before s…
  • Loading branch information
powerful23 authored May 3, 2019
2 parents 47c7cfd + 6e41aad commit f174ed1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/aws-amplify-react-native/src/Auth/withOAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default (Comp) => {
return class WithOAuth extends React.Component {
constructor(props) {
super(props);

this._isMounted = false;
const config = this._getOAuthConfig();

const {
Expand All @@ -49,17 +49,21 @@ export default (Comp) => {
}

componentDidMount() {
this._isMounted = true;
Auth.currentAuthenticatedUser().then(user => {
this.setState({ user })
}).catch(error => {
logger.debug(error);

this.setState({ user: null });
});
}

componentWillUnmount() {
this._isMounted = false;
return;
}
onHubCapsule(capsule) {
// The Auth module will emit events when user signs in, signs out, etc
if (!this._isMounted) return;
const { channel, payload } = capsule;

if (channel === 'auth') {
Expand All @@ -68,7 +72,6 @@ export default (Comp) => {
case 'cognitoHostedUI': {
Auth.currentAuthenticatedUser().then(user => {
logger.debug('signed in');

this.setState({ user, error: null });
});
break;
Expand Down

0 comments on commit f174ed1

Please sign in to comment.