Skip to content

Commit

Permalink
Merge pull request #17064 from mozilla/FXA-9663-p2
Browse files Browse the repository at this point in the history
bug(settings): Login breaking after swapping secondary and primary emails.
  • Loading branch information
dschom authored Jun 5, 2024
2 parents e2bce39 + 0cfad2e commit d5febb9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/fxa-auth-client/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ export default class AuthClient {
async signInWithAuthPW(
email: string,
authPW: string,
options: Omit<SignInOptions, 'skipCaseError' | 'originalLoginEmail'> = {},
options: SignInOptions = {},
headers?: Headers
): Promise<Omit<SignedInAccountData, 'unwrapBKey'>> {
const payloadOptions = ({ keys, ...rest }: any) => rest;
Expand Down
23 changes: 11 additions & 12 deletions packages/fxa-settings/src/pages/Signin/container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,30 +456,29 @@ describe('signin container', () => {
});

it('handles incorrect email case error', async () => {
const email = `orginal-${MOCK_EMAIL}`;
const correctedEmail = `new-${MOCK_EMAIL}`;
await render([
mockGqlAvatarUseQuery(),
// The first call should fail, and the incorrect email case error
// with the corrected email in the error response should be returned.
{
...mockGqlBeginSigninMutation(
{ keys: false },
{ email: MOCK_EMAIL.toUpperCase() }
),
...mockGqlBeginSigninMutation({ keys: false }, { email: email }),
error: mockGqlError(AuthUiErrors.INCORRECT_EMAIL_CASE, {
email: MOCK_EMAIL,
email: correctedEmail,
}),
},
// The corrected email should then be used, for the second attempt, and
// the login should succeed.
mockGqlBeginSigninMutation({
keys: false,
originalLoginEmail: MOCK_EMAIL.toUpperCase(),
}),
// Note, that originalEmail should also be sent up. This is a requirement for v1 passwords!
mockGqlBeginSigninMutation(
{ keys: false, originalLoginEmail: email },
{ email: correctedEmail }
),
]);

await waitFor(async () => {
// Emulates providing the original email even after they swapped in a primary email.
const handlerResult = await currentSigninProps?.beginSigninHandler(
MOCK_EMAIL.toUpperCase(),
email,
MOCK_PASSWORD
);
expect(handlerResult?.data).toBeDefined();
Expand Down
6 changes: 4 additions & 2 deletions packages/fxa-settings/src/pages/Signin/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,17 @@ export async function trySignIn(
const { v1Credentials, v2Credentials } = await onRetryCorrectedEmail(
result.error.email
);
options.originalLoginEmail = email;
// Try one more time with the corrected email
return trySignIn(
result.error.email,
v1Credentials,
v2Credentials,
unverifiedAccount,
beginSignin,
options
{
...options,
originalLoginEmail: email,
}
);
}

Expand Down

0 comments on commit d5febb9

Please sign in to comment.