Skip to content

Commit 5a1aa3a

Browse files
authored
Merge pull request #1833 from aws-amplify/reset-password-phone-fix
2 parents 194ba9f + b1656e1 commit 5a1aa3a

File tree

6 files changed

+60
-29
lines changed

6 files changed

+60
-29
lines changed

.changeset/green-terms-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/ui': patch
3+
---
4+
5+
Fixed bug with reset password for phone

packages/e2e/cypress/integration/common/shared.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,30 @@ When('I see {string} as the {string} input', (custom, order) => {
290290

291291
// cy.findByLabelText(custom).type(Cypress.env('VALID_PASSWORD'));
292292
});
293+
294+
When('I type a valid code', () => {
295+
/**
296+
* Confirmation code differs on React/Vue vs Angular. Testing for both for
297+
* now, but we can look to make them consistent on next major release.
298+
*/
299+
const regex = new RegExp(`^(confirmation )?code( *)?`, 'i');
300+
cy.findByRole('spinbutton', { name: regex }).type('1234');
301+
});
302+
303+
Then('I will be redirected to the confirm forgot password page', () => {
304+
cy.findInputField('New Password').should('exist');
305+
});
306+
307+
When('I type my new password', () => {
308+
cy.findInputField('New Password').type(Cypress.env('VALID_PASSWORD'));
309+
});
310+
311+
Then('I click the submit button', () => {
312+
/**
313+
* Submit button text differs on React/Vue vs Angular. Testing for both for
314+
* now, but we can look to make them consistent on next major release.
315+
*/
316+
cy.findByRole('button', {
317+
name: new RegExp(`^((submit)|(send code))$`, 'i'),
318+
}).click();
319+
});
Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1 @@
11
import { Then, When } from 'cypress-cucumber-preprocessor/steps';
2-
3-
Then('I will be redirected to the confirm forgot password page', () => {
4-
cy.findInputField('New Password').should('exist');
5-
});
6-
7-
When('I type my new password', () => {
8-
cy.findInputField('New Password').type(Cypress.env('VALID_PASSWORD'));
9-
});
10-
11-
Then('I click the submit button', () => {
12-
/**
13-
* Submit button text differs on React/Vue vs Angular. Testing for both for
14-
* now, but we can look to make them consistent on next major release.
15-
*/
16-
cy.findByRole('button', {
17-
name: new RegExp(`^((submit)|(send code))$`, 'i'),
18-
}).click();
19-
});
20-
21-
When('I type a valid code', () => {
22-
/**
23-
* Confirmation code differs on React/Vue vs Angular. Testing for both for
24-
* now, but we can look to make them consistent on next major release.
25-
*/
26-
const regex = new RegExp(`^(confirmation )?code( *)?`, 'i');
27-
cy.findByRole('spinbutton', { name: regex }).type('1234');
28-
});

packages/e2e/features/ui/components/authenticator/sign-in-with-phone.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ Feature: Sign In with Phone Number
1010
Background:
1111
Given I'm running the example "ui/components/authenticator/sign-in-with-phone"
1212

13+
@angular @react @vue
14+
Scenario: Reset Password with valid phone with country code
15+
When I click the "Forgot your password?" button
16+
When I select my country code with status "CONFIRMED"
17+
And I type my "phone number" with status "CONFIRMED"
18+
And I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.ForgotPassword" } }' with fixture "reset-password"
19+
And I click the "Send code" button
20+
And I verify the body has "+19995554444" included
21+
Then I will be redirected to the confirm forgot password page
22+
And I see "Code"
23+
Then I type a valid code
24+
And I type my new password
25+
And I confirm my password
26+
And I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.ConfirmForgotPassword" } }' with fixture "confirm-reset-password"
27+
And I click the submit button
28+
And I verify the body has "+19995554444" included
29+
Then I see "Sign In"
30+
1331
@angular @react @vue
1432
Scenario: Sign in and replace default dial code
1533
Then I see "Sign In"

packages/ui/src/machines/authenticator/actions.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,15 @@ export const setUser = assign({
105105
});
106106

107107
export const setUsername = assign({
108-
username: (context: ActorContextWithForms, _) => context.formValues.username,
108+
username: (context: ActorContextWithForms, _) => {
109+
let {
110+
formValues: { username, country_code },
111+
} = context;
112+
if (country_code) {
113+
username = `${country_code}${username}`;
114+
}
115+
return username;
116+
},
109117
});
110118

111119
export const setCodeDeliveryDetails = assign({

packages/ui/src/machines/authenticator/actors/resetPassword.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function resetPasswordActor({ services }: ResetPasswordMachineOptions) {
183183
},
184184
services: {
185185
async resetPassword(context) {
186-
const username = context.formValues?.username ?? context.username;
186+
const { username } = context;
187187

188188
return services.handleForgotPassword(username);
189189
},

0 commit comments

Comments
 (0)