Skip to content

Commit 8418028

Browse files
ErikCHErik Hanchett
andauthored
fix: MFA TOTP sign up - user is not set correctly (#2287)
* Fix error with signup * Remove comment * Changed from email to username * Fixed username * Fixed for existing users * Fixed test, and removed additional setuser that was causing an issue * Removed additional useAuthenticator call * Updated user in next example Co-authored-by: Erik Hanchett <[email protected]>
1 parent bc63b7c commit 8418028

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

.changeset/rare-bananas-destroy.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+
When first setting up TOTP with MFA the Authenticator is not returning the correct user object. This object did not contain the correct methods, and causes an error if you try to access those methods. This fix will now retrieve the correct user object when a user first sets up MFA TOTP.

examples/next/pages/ui/components/authenticator/sign-in-totp-mfa/index.page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ Amplify.configure(awsExports);
88

99
export default function SignInTotpMfa() {
1010
const formFields = { setupTOTP: { QR: { totpIssuer: 'My Web App' } } };
11+
1112
return (
1213
<>
1314
<Authenticator formFields={formFields}>
14-
{({ signOut }) => <button onClick={signOut}>Sign out</button>}
15+
{({ signOut, user }) => (
16+
<>
17+
<span>{user.username}</span>
18+
<button onClick={signOut}>Sign out</button>
19+
</>
20+
)}
1521
</Authenticator>
1622
</>
1723
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"challengeName": "MFA_SETUP",
3+
"username": "AmplifyUsername",
4+
"challengeParameters": {
5+
"MFAS_CAN_SETUP": "[\"SMS_MFA\",\"SOFTWARE_TOKEN_MFA\"]"
6+
},
7+
"session": "••••••"
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"AuthenticationResult": {
3+
"AccessToken": "***************",
4+
"ExpiresIn": 3600,
5+
"IdToken": "*****************",
6+
"RefreshToken": "****************",
7+
"TokenType": "Bearer"
8+
},
9+
"ChallengeParameters": {}
10+
}

packages/e2e/features/ui/components/authenticator/sign-in-totp-mfa.feature

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,21 @@ Feature: Sign In with TOTP MFA
5757
And I click the "Change Password" button
5858
Then I see "Setup TOTP"
5959

60-
60+
@angular @react @vue
61+
Scenario: Successful sign up shows correct username from authenticated user
62+
When I click the "Create Account" tab
63+
And I type a new "email"
64+
And I type my password
65+
And I confirm my password
66+
And I click the "Create Account" button
67+
Then I see "Confirmation Code"
68+
And I type a valid confirmation code
69+
And I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.ConfirmSignUp" } }' with fixture "confirm-sign-up-with-email"
70+
And I mock 'Amplify.Auth.signIn' with fixture "Auth.signIn-mfa-setup"
71+
And I click the "Confirm" button
72+
Then I see "Setup TOTP"
73+
Then I see "Code"
74+
And I type a valid confirmation code
75+
And I mock 'Amplify.Auth.verifyTotpToken' with fixture "Auth.verifyTOTP"
76+
And I click the "Confirm" button
77+
Then I see "AmplifyUsername"

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,7 @@ export function signInActor({ services }: SignInMachineOptions) {
343343
invoke: {
344344
src: 'verifyTotpToken',
345345
onDone: {
346-
actions: [
347-
'setUser',
348-
'clearChallengeName',
349-
'clearRequiredAttributes',
350-
],
346+
actions: ['clearChallengeName', 'clearRequiredAttributes'],
351347
target: '#signInActor.resolved',
352348
},
353349
onError: {

0 commit comments

Comments
 (0)