Amplify-js: Lib throws "Username cannot be empty" on SignUp when no "username" needed for sign up

Created on 20 Jun 2018  路  6Comments  路  Source: aws-amplify/amplify-js

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Lib throws

Username cannot be empty

What is the expected behavior?

Accept signUp action without errors.

Example

I've set up my cognito so that it doesn't use username, only email and password.
So why your lib throws Username cannot be empty? This is definitely wrong behaviour!

If I call .signUp this way (params as strings, no username), all works as expected, no errors thrown:

Auth.signUp(email, password)
    .then( data => {
        // All is OK, we here
    } )
    .catch( err => {

    } );

If I call this way (params as an object), your SDK throws. Why? It is not consistent. I need to call this way because I have attributes to pass to Cognito.

See your docs https://aws.github.io/aws-amplify/media/authentication_guide#working-with-user-attributes, I need to use object params, but it doesn't work when object!

Auth.signUp( {email, password, attributes: {
    foo: 'bar'
}})
    .then( data => {
    } )
    .catch( err => {
        // `Username cannot be empty` // Why?
    } );
Auth Cognito

Most helpful comment

Ah I see a potential error. Even though it is set to email, you have to pass the email as the username like my function below. I would agree that it doesn't make much sense but you have to do it similar to this way.

      Auth.signUp({
        username: this.signupForm.get('email').value.toLowerCase( ),
        password: this.signupForm.get('password').value,
        attributes: {
          email: this.signupForm.get('email').value.toLowerCase( ),
          given_name: this.signupForm.get('given_name').value,
          family_name: this.signupForm.get('family_name').value
        },
        validationData: []
      }).then(() => {
          this.router.navigate(['unverified']);
        }).catch(err => {
          this.errorMessage = err;
        });

All 6 comments

I had a very similar issue too, when you go into AWS cognito make sure that the signup type is set to email not username or email aliases configurations. I would recommend walking through in the UI the creation of the user pool in the aws mobilehub to see what you can do.

@dallinwright
It is already set. That's why I don't understand their error

screen shot 2018-06-20 at 5 34 29 pm

Ah I see a potential error. Even though it is set to email, you have to pass the email as the username like my function below. I would agree that it doesn't make much sense but you have to do it similar to this way.

      Auth.signUp({
        username: this.signupForm.get('email').value.toLowerCase( ),
        password: this.signupForm.get('password').value,
        attributes: {
          email: this.signupForm.get('email').value.toLowerCase( ),
          given_name: this.signupForm.get('given_name').value,
          family_name: this.signupForm.get('family_name').value
        },
        validationData: []
      }).then(() => {
          this.router.navigate(['unverified']);
        }).catch(err => {
          this.errorMessage = err;
        });

Feel free to reopen it if you are still facing this issue.

I have the same issue using the react aws-amplify lib.

Here is the documentation about this topic:

https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases-settings-option-2

Was this page helpful?
0 / 5 - 0 ratings