Skip to content

Commit

Permalink
feat(@aws-amplify/ui-components): add hideToast prop to authenticator (
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke-Davies authored and Daniel Gonzalez committed Mar 18, 2021
1 parent 1967112 commit 4590505
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/amplify-ui-components/src/components.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export class AmplifyAuthenticator {
@Prop() usernameAlias: UsernameAliasStrings;
/** Callback for Authenticator state machine changes */
@Prop() handleAuthStateChange: AuthStateHandler = () => {};
/** Hide amplify-toast for auth errors */
@Prop() hideToast: boolean = false;

@State() authState: AuthState = AuthState.Loading;
@State() authData: CognitoUserInterface;
Expand Down Expand Up @@ -83,7 +85,7 @@ export class AmplifyAuthenticator {
this.onAuthStateChange(authState, authData as CognitoUserInterface);
this.toastMessage = '';
});
Hub.listen(UI_AUTH_CHANNEL, this.handleToastEvent);
if (!this.hideToast) Hub.listen(UI_AUTH_CHANNEL, this.handleToastEvent);
Hub.listen(AUTH_CHANNEL, this.handleExternalAuthEvent);

appendToCognitoUserAgent('amplify-authenticator');
Expand Down Expand Up @@ -180,22 +182,22 @@ export class AmplifyAuthenticator {

componentWillUnload() {
Hub.remove(AUTH_CHANNEL, this.handleExternalAuthEvent);
Hub.remove(UI_AUTH_CHANNEL, this.handleToastEvent);
if (!this.hideToast) Hub.remove(UI_AUTH_CHANNEL, this.handleToastEvent);
return onAuthUIStateChange;
}

render() {
return (
<Host>
{this.toastMessage ? (
{!this.hideToast && this.toastMessage && (
<amplify-toast
message={this.toastMessage}
handleClose={() => {
this.toastMessage = '';
}}
data-test="authenticator-error"
/>
) : null}
)}
{this.authState === AuthState.SignedIn ? (
[<slot name="greetings"></slot>, <slot></slot>]
) : (
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4590505

Please sign in to comment.