fix(gen2-migration): preserve email verification disabled setting (#14810)#14847
Draft
fix(gen2-migration): preserve email verification disabled setting (#14810)#14847
Conversation
When a Gen1 auth resource had email-based verification disabled
(autoVerifiedAttributes: ["phone_number"] only), the migration
tool incorrectly generated `loginWith: { email: true }` instead
of `loginWith: { phone: true }`.
The fix checks AutoVerifiedAttributes on the user pool: when it
contains only phone_number (not email), the renderer now emits
`phone: true` in the loginWith block, preserving the original
SMS-based verification behavior.
Added a test case that verifies the phone-only verification
scenario with email as a required-but-not-verified attribute.
---
Prompt: Fix issue #14810 — generate step does not preserve
"Email based user registration/forgot password: Disabled"
setting when autoVerifiedAttributes is ["phone_number"].
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solves #14810.
Issue Summary
The
generatestep does not preserve the "Email based user registration/forgot password: Disabled" setting from Gen 1. WhenautoVerifiedAttributesis["phone_number"](not["email"]), the migration tool incorrectly generatesloginWith: { email: true }instead ofloginWith: { phone: true }, switching verification from SMS to email.Reasoning
autoVerifiedAttributes: ["phone_number"]get migrated tologinWith: { email: true }, which changes the verification channel from SMS to email.auth.renderer.ts— found thebuildLoginWithmethod which unconditionally emits eitheremail: trueor an email options object. It never checksautoVerifiedAttributesto determine whether phone-based verification was configured.AutoVerifiedAttributesfrom the fetched user pool config: if it containsphone_numberbut notemail, the user had email verification disabled and we should emitphone: trueinstead.options.userPool.AutoVerifiedAttributesarray is already available in the render options passed tobuildLoginWith.Solution
auth.renderer.ts— InbuildLoginWith, added a check forisPhoneOnlyVerification(autoVerified includesphone_numberbut notemail). When true, emitsloginWith: { phone: true }instead ofloginWith: { email: true }. The existing email verification message/subject logic is preserved in theelsebranch.auth.generator.test.ts— Added a new test case'generates phone login when email verification is disabled'that mocks a user pool withAutoVerifiedAttributes: ['phone_number']andUsernameAttributes: ['phone_number'], and asserts the generatedresource.tscontainsloginWith: { phone: true }withemailas a required-but-not-verified user attribute.Example
Input (Gen 1 — cli-inputs.json):
{ "cognitoConfig": { "autoVerifiedAttributes": ["phone_number"], "requiredAttributes": ["email"] } }Output — before fix (resource.ts):
Output — after fix (resource.ts):