Skip to content

fix(cli): preserve phone-based sign-in in gen2 migration - #14969

Merged
sharonyajain merged 2 commits into
aws-amplify:devfrom
sharonyajain:cli/gen2-migration-preserve-phone-login
Aug 12, 2026
Merged

fix(cli): preserve phone-based sign-in in gen2 migration#14969
sharonyajain merged 2 commits into
aws-amplify:devfrom
sharonyajain:cli/gen2-migration-preserve-phone-login

Conversation

@sharonyajain

Copy link
Copy Markdown
Contributor

Description of changes

The Gen2 migration auth renderer (packages/amplify-cli/src/commands/gen2-migration/generate/amplify/auth/auth.renderer.ts) unconditionally emitted loginWith.email and never emitted loginWith.phone. As a result, Gen1 Cognito user pools that verify via phone_number (email verification disabled, using SMS/TOTP) were migrated to email-based login, breaking parity for sign-in, auto-verification, and forgot-password.

This change derives the login mechanisms from the source pool's UsernameAttributes, AliasAttributes, and AutoVerifiedAttributes, emitting phone and/or email to match the Gen1 configuration. It falls back to email only when neither is present (since defineAuth requires at least one). Email is preserved as a required user attribute when it is not a sign-in mechanism.

Issue #, if available

Addresses part of #14810 (the loginWith mechanism). The SMS configuration / SNS caller-role carry-over described in that issue is a separate concern (Gen2 defineAuth does not auto-provision an SNS role from loginWith: { phone: true })
and is tracked as a follow-up.

Description of how you validated changes

  • Corrected the existing generates phone login unit test snapshot, which previously asserted the buggy loginWith: { email: true } output for a phone-based pool.
  • Added a regression test for the exact issue scenario (email verification disabled, AutoVerifiedAttributes: ['phone_number'], email as a required attribute) asserting phone: true and no email login.
  • Updated the discussions and media-vault migration-app snapshots to reflect correct phone/combined login.
  • yarn test for the gen2-migration suite: 432/432 tests pass across 48 suites.

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The gen2 migration auth renderer unconditionally emitted loginWith.email
and never emitted loginWith.phone, so Gen1 user pools that verify via
phone_number (email verification disabled) were migrated to email login.
This broke sign-in, auto-verification, and forgot-password parity.

Derive login mechanisms from the source pool's UsernameAttributes,
AliasAttributes, and AutoVerifiedAttributes, emitting phone and/or email
to match Gen1 (falling back to email when neither is present, since
defineAuth requires at least one). Email is kept as a required user
attribute when it is not a sign-in mechanism.

Refs aws-amplify#14810
@sharonyajain
sharonyajain requested a review from a team as a code owner August 10, 2026 14:02
@sharonyajain sharonyajain self-assigned this Aug 10, 2026

@soberm soberm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went through the diff. The fix looks solid overall. good regression test tied directly to #14810, and a sensible call to scope the SNS/SMS follow-up out rather than cramming it into this PR.

…tion

Address PR review feedback:
- Weight UsernameAttributes/AliasAttributes over AutoVerifiedAttributes when
  deriving login mechanisms. Auto-verify only controls verification-code
  delivery and does not by itself make an attribute a usable sign-in method,
  so it is now consulted only when no sign-in attribute is populated.
- Add unit tests for the AliasAttributes source and for a pool that enables
  both email and phone sign-in.
- Tighten the regression test assertion to pin email under userAttributes.

Refs aws-amplify#14810
@sharonyajain
sharonyajain merged commit 078f78d into aws-amplify:dev Aug 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants