Amplify-js: (BUG) Auth signUp give wrong error message

Created on 7 Apr 2020  路  10Comments  路  Source: aws-amplify/amplify-js

Describe the bug

Auth signUp give wrong Error information when it receives InvalidParameterException,

It will always show Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters.

aws-amplify Version

3.0.5

Desktop:

OS: macOS Catalina
Node Version: v13.5.0
Project: React Native

To Reproduce

I created a React Native app in which I use Auth. My schema looks like this:

in App.tsx

Amplify.configure({
      Auth: {
        userPoolId: "****",
        region: "****",
        userPoolWebClientId: "***",
      },
    });

sign up code:

try {
      const result = await Auth.signUp({
        username: data.username,
        password: data.password,
        attributes: {
          email: data.email, // optional
          phone_number: data.phone, // optional - E.164 number convention
          name: data.fullName,
        },
      });
      console.log(result);
    } catch (err) {
      console.log(err.message);
      throw new Error(err.message);
    }

Expected behavior

In this case, when the phone number is not in the correct format, I expect the API returns the Error msg related to the phone number format error.

While I get Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters. instead.

What I found

After I investigating the RN network request, I found the actual error in the responseHeaders.

responseHeaders: {
  x-amzn-errormessage: "Invalid phone number format",
  x-amzn-errortype: "InvalidParameterException"
}

WechatIMG35

And I found this in the source code amplify-js/packages/auth/src/Auth.ts in the line 310

WX20200407-134859@2x

https://github.com/aws-amplify/amplify-js/blob/c11955da9964b681b758098bdf80078215a90bd6/packages/auth/src/Auth.ts#L310

I hope this ticket can help to fix the problem and the Auth signup should throw the actual error return from the server.

React Native

Most helpful comment

This is occurring with aws-amplify-react as well.

When sending the sign up request to Cognito with a password that doesn't meet the password requirements, Cognito returns the following response:

{
  "__type":"InvalidParameterException",
  "message":"1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length greater than or equal to 6"
}

When sending the sign up request to Cognito with a username that is expected to be an email, Cognito returns the following response:

{"__type":"InvalidParameterException","message":"Username should be an email."}

However Amplify always renders:

Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters

All 10 comments

@ansoncen Can you provide the format of what your phone number looks like that you are passing? I am seeing the message of Invalid phone number format so would like to confirm. Thanks ahead of time

This is occurring with aws-amplify-react as well.

When sending the sign up request to Cognito with a password that doesn't meet the password requirements, Cognito returns the following response:

{
  "__type":"InvalidParameterException",
  "message":"1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length greater than or equal to 6"
}

When sending the sign up request to Cognito with a username that is expected to be an email, Cognito returns the following response:

{"__type":"InvalidParameterException","message":"Username should be an email."}

However Amplify always renders:

Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters

This is occurring with aws-amplify-react as well.

When sending the sign up request to Cognito with a password that doesn't meet the password requirements, Cognito returns the following response:

{
  "__type":"InvalidParameterException",
  "message":"1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length greater than or equal to 6"
}

When sending the sign up request to Cognito with a username that is expected to be an email, Cognito returns the following response:

{"__type":"InvalidParameterException","message":"Username should be an email."}

However Amplify always renders:

Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters

Agree, I think this is what @ansoncen want to express: the error message is not precise enough, which makes developer hard to locate the real problem.

@ansoncen Can you provide the format of what your phone number looks like that you are passing? I am seeing the message of Invalid phone number format so would like to confirm. Thanks ahead of time

hey @sammartinez , some random characters in phone_number can reproduce the issues.

for example

const data = {
username: "abcdefg",
password: "12345678",
email: "[email protected]"
}

 try {
      const result = await Auth.signUp({
        username: data.username,
        password: data.password,
        attributes: {
          email: data.email,
          phone_number: "abcdefgh", // optional - E.164 number convention
        },
      });
      return result;
    } catch (err) {
      console.log(err.message);
      throw new Error(err.message);
    }

The error caught and console log will be Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters.

The expected error information should link to the phone_number instead of the username.

I encounter similar strange behavior but with different input (considering default pw policy with minimum 8 characters and at least one number):

using '123' as password gives:

{"__type":"InvalidParameterException","message":"1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length greater than or equal to 6"}

using '123123' as password gives:

{"__type":"InvalidPasswordException","message":"Password did not conform with policy: Password not long enough"}

For me it would be enough when error types are InvalidPasswordException if they are related to password and InvalidEmailException if they are related to email. A more generic approach would also be fine if all errors are "type": "InvalidParameterException" but have an additional property that holds the parameter name.

I think I know the root cause, it was because of an incorrect merge that caused a previous reverted commit to reappear. I'm reverting that.

I'm still seeing this error. I'm testing Auth.signUp locally with invalid usernames / passwords to see what the returned error messages are.

I pass the string "asdfasdf" to the username field. My Cognito is configured to expect emails as usernames only. The network request to Cognito errors with the message
{__type: "InvalidParameterException", message: "Invalid email address format."}
but the error message I see printed to console is
{code: "InvalidParameterException", name: "InvalidParameterException", message: "Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters."}.

This is the code that I'm using:

Auth.signUp({
      username: email,
      password: password,
      attributes: {
        email: email
      },
      validationData: []
    }).then(data => console.log(data)).catch(err => console.log(err));

Describe the bug

Auth signUp give wrong Error information when it receives InvalidParameterException,

It will always show Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters.

aws-amplify Version

3.0.5

Desktop:

OS: macOS Catalina
Node Version: v13.5.0
Project: React Native

To Reproduce

I created a React Native app in which I use Auth. My schema looks like this:

in App.tsx

Amplify.configure({
      Auth: {
        userPoolId: "****",
        region: "****",
        userPoolWebClientId: "***",
      },
    });

sign up code:

try {
      const result = await Auth.signUp({
        username: data.username,
        password: data.password,
        attributes: {
          email: data.email, // optional
          phone_number: data.phone, // optional - E.164 number convention
          name: data.fullName,
        },
      });
      console.log(result);
    } catch (err) {
      console.log(err.message);
      throw new Error(err.message);
    }

Expected behavior

In this case, when the phone number is not in the correct format, I expect the API returns the Error msg related to the phone number format error.

While I get Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters. instead.

What I found

After I investigating the RN network request, I found the actual error in the responseHeaders.

responseHeaders: {
  x-amzn-errormessage: "Invalid phone number format",
  x-amzn-errortype: "InvalidParameterException"
}

WechatIMG35

And I found this in the source code amplify-js/packages/auth/src/Auth.ts in the line 310

WX20200407-134859@2x

https://github.com/aws-amplify/amplify-js/blob/c11955da9964b681b758098bdf80078215a90bd6/packages/auth/src/Auth.ts#L310

I hope this ticket can help to fix the problem and the Auth signup should throw the actual error return from the server.

""Username could not be created. Please make sure that the username you have entered is between 1 and 128 characters." - is happen to me doesnt matter what I change in my code ....

Same issue with the React <AmplifySignUp>-component. Entering an invalid phone number show the username error.

image

Webpack used for building with:

 "react": "^16.13.1",
 "aws-amplify": "^3.0.7",
 "@aws-amplify/ui-react": "^0.2.2",

3.0.8-unstable.9 works from me.

Was this page helpful?
0 / 5 - 0 ratings