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

fix(aws-amplify-react-native): Update Hub listener for sign out events #5587

Merged
merged 8 commits into from Apr 30, 2020
43 changes: 32 additions & 11 deletions packages/aws-amplify-react-native/src/Auth/Authenticator.js
Expand Up @@ -80,23 +80,44 @@ export default class Authenticator extends React.Component {
}

onHubCapsule(capsule) {
const { channel, payload, source } = capsule;
if (channel === 'auth') {
this.checkUser();
const {
payload: { event, data },
} = capsule;
switch (event) {
case 'cognitoHostedUI':
return this.handleStateChange('signedIn', data);

case 'cognitoHostedUI_failure':
case 'parsingUrl_failure':
case 'signOut':
case 'customGreetingSignOut':
return this.handleStateChange('signIn', null);
}
}

handleStateChange(state, data) {
logger.debug('authenticator state change ' + state);
if (!this._isMounted) return;
if (state === this.state.authState) {
return;
if (state === undefined)
return logger.info('Auth state cannot be undefined');

logger.info(
'Inside handleStateChange method current authState:',
this.state.authState
);

const nextAuthState =
state === 'signedOut' ? this._initialAuthState : state;
const nextAuthData = data !== undefined ? data : this.state.authData;

if (this._isMounted) {
this.setState({
authState: nextAuthState,
authData: nextAuthData,
error: null,
});
logger.log('Auth Data was set:', nextAuthData);
logger.info(`authState has been updated to ${nextAuthState}`);
}

if (state === 'signedOut') {
state = 'signIn';
}
this.setState({ authState: state, authData: data, error: null });
if (this.props.onStateChange) {
this.props.onStateChange(state, data);
}
Expand Down