Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imported auth has incomplete username_attributes in frontend config file #13852

Open
2 tasks done
edwardfoyle opened this issue Jul 11, 2024 · 1 comment
Open
2 tasks done
Labels
auth Issues tied to the auth category of the CLI bug Something isn't working p2

Comments

@edwardfoyle
Copy link
Contributor

edwardfoyle commented Jul 11, 2024

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

20

Amplify CLI Version

12.12.4

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

N/A

Describe the bug

When importing a Cognito User Pool that contains user attributes as email and phone number, the amplifyconfiguration.json file shows email only:

  "aws_cognito_username_attributes": [
    "EMAIL"
  ],

Expected behavior

Importing auth with email and phone username attributes should include both values in frontend config output.

Reproduction steps

Create Amplify-generated User Pool with user attributes.

amplify init
amplify add auth
a. Ensure that How do you want users to be able to sign in? Email or Phone Number is selected.
amplify push -y

Observe amplifyconfiguration.json as

{
  "aws_project_region": "us-east-1",
  "aws_cognito_region": "us-east-1",
  "aws_user_pools_id": "us-east-1_64iSuUnbm",
  "aws_user_pools_web_client_id": "7ec82dck4mlai0bf43c5dlvupt",
  "oauth": {},
  "aws_cognito_username_attributes": [
    "EMAIL",
    "PHONE_NUMBER"
  ],
  "aws_cognito_social_providers": [],
  "aws_cognito_signup_attributes": [
    "EMAIL"
  ],
  "aws_cognito_mfa_configuration": "OFF",
  "aws_cognito_mfa_types": [
    "SMS"
  ],
  "aws_cognito_password_protection_settings": {
    "passwordPolicyMinLength": 8,
    "passwordPolicyCharacters": []
  },
  "aws_cognito_verification_mechanisms": [
    "EMAIL"
  ]
}

Create another Amplify application with imported User Pool:

amplify init
amplify import auth
a. Use User Pool only (no identiity pool)
Select the Amplify-generated User Pool and client ID from the previous steps.
amplify push -y

Observe amplifyconfiguration.json file

{
  "aws_project_region": "us-east-1",
  "aws_cognito_region": "us-east-1",
  "aws_user_pools_id": "us-east-1_64iSuUnbm",
  "aws_user_pools_web_client_id": "7ec82dck4mlai0bf43c5dlvupt",
  "oauth": {},
  "aws_cognito_username_attributes": [
    "EMAIL"
  ],
  "aws_cognito_social_providers": [],
  "aws_cognito_signup_attributes": [
    "EMAIL"
  ],
  "aws_cognito_mfa_configuration": "OFF",
  "aws_cognito_mfa_types": [],
  "aws_cognito_password_protection_settings": {
    "passwordPolicyMinLength": 8,
    "passwordPolicyCharacters": []
  },
  "aws_cognito_verification_mechanisms": [
    "EMAIL"
  ]
}

Specifically noting that one has aws_cognito_username_attributes as EMAIL and the other has it set as EMAIL, PHONE_NUMBER

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@edwardfoyle edwardfoyle added pending-triage Issue is pending triage bug Something isn't working auth Issues tied to the auth category of the CLI and removed pending-triage Issue is pending triage labels Jul 11, 2024
@edwardfoyle
Copy link
Contributor Author

I was able to work around the issue by creating a post-push script to override the output content.

amplify/hooks/post-push.sh:

tmp=$(mktemp)
jq '.aws_cognito_username_attributes = ["EMAIL", "PHONE_NUMBER"]' src/amplifyconfiguration.json > "$tmp"
mv "$tmp" src/amplifyconfiguration.json

@sobolk sobolk added the p2 label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues tied to the auth category of the CLI bug Something isn't working p2
Projects
None yet
Development

No branches or pull requests

2 participants