Skip to content

Commit

Permalink
fix(authenticator): propagate username from signUp actor to top level…
Browse files Browse the repository at this point in the history
… machine (#4923)
  • Loading branch information
calebpollman authored Jan 22, 2024
1 parent 0ac1fab commit d61690d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .changeset/new-badgers-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@aws-amplify/ui": patch
"@aws-amplify/ui-vue": patch
---

fix(authenticator): propagate username from signUp actor to top level machine
1 change: 1 addition & 0 deletions packages/ui/src/machines/authenticator/actors/signUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export function signUpActor({ services }: SignUpMachineOptions) {
remoteError: context.remoteError,
step: context.step,
totpSecretCode: context.totpSecretCode,
username: context.username,
unverifiedUserAttributes: context.unverifiedUserAttributes,
}),
},
Expand Down
12 changes: 0 additions & 12 deletions packages/vue/src/components/__tests__/setup-totp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,6 @@ describe('SetupTotp', () => {
);
});

it('does not call getTotpCodeURL if totpCodeURL is not present', () => {
useAuthenticatorSpy.mockReturnValue(
reactive({
...mockServiceFacade,
totpSecretCode: undefined,
})
);

render(SetupTotp, { global: { components } });
expect(getTotpCodeURLSpy).not.toHaveBeenCalled();
});

it('renders error if present', async () => {
useAuthenticatorSpy.mockReturnValueOnce(
reactive({
Expand Down
20 changes: 8 additions & 12 deletions packages/vue/src/components/setup-totp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ const logger = new Logger('SetupTotp-logger');
// `facade` is manually typed to `UseAuthenticator` for temporary type safety.
const facade: UseAuthenticator = useAuthenticator();
const { updateForm, submitForm, toSignIn } = facade;
const { error, isPending, QRFields, totpSecretCode, username } = toRefs(facade);
const { updateForm, submitForm, toSignIn, totpSecretCode, username, QRFields } =
facade;
const { error, isPending } = toRefs(facade);
const { totpIssuer = 'AWSCognito', totpUsername = username.value } =
QRFields.value ?? {};
const { totpIssuer = 'AWSCognito', totpUsername = username } = QRFields ?? {};
const totpCodeURL = totpSecretCode.value
? getTotpCodeURL(totpIssuer, totpUsername!, totpSecretCode.value)
: null;
// `totpSecretCode` is typed as `string | null` but will always be populated by the machine here
const totpCodeURL = getTotpCodeURL(totpIssuer, totpUsername, totpSecretCode!);
const qrCode = reactive({
qrCodeImageSource: '',
Expand All @@ -40,17 +39,14 @@ const { getCopyText, getCopiedText, getBackToSignInText, getConfirmText } =
const copyTextLabel = ref(getCopyText());
function copyText() {
if (totpSecretCode.value) {
navigator.clipboard.writeText(totpSecretCode.value);
if (totpSecretCode) {
navigator.clipboard.writeText(totpSecretCode);
}
copyTextLabel.value = getCopiedText();
}
// lifecycle hooks
onMounted(async () => {
if (!username.value || !totpCodeURL) {
return;
}
try {
qrCode.qrCodeImageSource = await QRCode.toDataURL(totpCodeURL);
} catch (error) {
Expand Down

0 comments on commit d61690d

Please sign in to comment.