Skip to content

Commit

Permalink
Fix regression in react/react-native Authenticator (aws-amplify#6508)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanranz authored Aug 6, 2020
1 parent d892fec commit 7d17aee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/aws-amplify-react-native/src/Auth/Authenticator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export default class Authenticator extends React.Component<
switch (event) {
case 'cognitoHostedUI':
case 'signIn':
return this.handleStateChange('signedIn', data);

this.checkContact(data);
break;
case 'cognitoHostedUI_failure':
case 'parsingUrl_failure':
case 'signOut':
Expand Down
26 changes: 24 additions & 2 deletions packages/aws-amplify-react/src/Auth/Authenticator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
*/

import * as React from 'react';
import { Amplify, I18n, ConsoleLogger as Logger, Hub } from '@aws-amplify/core';
import {
Amplify,
I18n,
ConsoleLogger as Logger,
Hub,
isEmpty,
} from '@aws-amplify/core';
import { Auth } from '@aws-amplify/auth';
import { Greetings } from './Greetings';
import { SignIn } from './SignIn';
Expand Down Expand Up @@ -134,13 +140,29 @@ export class Authenticator extends React.Component<
});
}

checkContact(user, changeState) {
if (!Auth || typeof Auth.verifiedContact !== 'function') {
throw new Error(
'No Auth module found, please ensure @aws-amplify/auth is imported'
);
}
Auth.verifiedContact(user).then(data => {
if (!isEmpty(data.verified)) {
changeState('signedIn', user);
} else {
user = Object.assign(user, data);
changeState('verifyContact', user);
}
});
}

onHubCapsule(capsule) {
const { channel, payload, source } = capsule;
if (channel === 'auth') {
switch (payload.event) {
case 'cognitoHostedUI':
case 'signIn':
this.handleStateChange('signedIn', payload.data);
this.checkContact(payload.data, this.handleStateChange);
break;
case 'cognitoHostedUI_failure':
this.handleStateChange('signIn', null);
Expand Down

0 comments on commit 7d17aee

Please sign in to comment.