Skip to content

Commit

Permalink
Use empty username check instead
Browse files Browse the repository at this point in the history
  • Loading branch information
wlee221 committed Feb 1, 2021
1 parent a188cb9 commit cc36343
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 0 additions & 2 deletions packages/amplify-ui-components/src/common/Translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export enum AuthStrings {
NEW_PASSWORD_PLACEHOLDER = 'Enter your new password',
NO_ACCOUNT_TEXT = 'No account?',
USERNAME_REMOVE_WHITESPACE = 'Username cannot contain whitespace',
EMAIL_REMOVE_WHITESPACE = 'Email cannot contain whitespace',
PHONE_REMOVE_WHITESPACE = 'Phone number cannot contain whitespace',
PASSWORD_REMOVE_WHITESPACE = 'Password cannot start or end with whitespace',
PASSWORD_LABEL = 'Password *',
PASSWORD_PLACEHOLDER = 'Enter your password',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,18 @@ export class AmplifySignUp {
switch (this.usernameAlias) {
case 'email':
case 'phone_number':
this.signUpAttributes.username = this.signUpAttributes.attributes[this.usernameAlias] || '';
this.signUpAttributes.username = this.signUpAttributes.attributes[this.usernameAlias];
break;
case 'username':
default:
break;
}
try {
if (!this.signUpAttributes.username) {
throw new Error(Translations.EMPTY_USERNAME);
}
if (this.signUpAttributes.username.indexOf(' ') >= 0) {
switch (this.usernameAlias) {
case 'username':
throw new Error(Translations.USERNAME_REMOVE_WHITESPACE);
case 'email':
throw new Error(Translations.EMAIL_REMOVE_WHITESPACE);
case 'phone_number':
throw new Error(Translations.PHONE_REMOVE_WHITESPACE);
}
throw new Error(Translations.USERNAME_REMOVE_WHITESPACE);
}
if (this.signUpAttributes.password !== this.signUpAttributes.password.trim()) {
throw new Error(Translations.PASSWORD_REMOVE_WHITESPACE);
Expand Down

0 comments on commit cc36343

Please sign in to comment.