Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(account-settings): Add back SetupTOTP #3149

Merged

Conversation

wlee221
Copy link
Contributor

@wlee221 wlee221 commented Dec 7, 2022

Description of changes

AccountSettings.SetupTOTP was previously descoped out of preview release. Adding this back. The code was reviewed in #2969, but there are few updates:

  • Renamed ConfigureTOTP -> AccountSettings.SetupTOTP
  • Used the new TS pattern for override components type
  • Use new classname pattern

Issue #, if available

Description of how you validated changes

Unit tests

Checklist

  • PR description included
  • yarn test passes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@wlee221 wlee221 requested a review from a team as a code owner December 7, 2022 19:28
@changeset-bot
Copy link

changeset-bot bot commented Dec 7, 2022

⚠️ No Changeset found

Latest commit: 68cafa2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines 12 to 14
export const ConfirmationCode: TextFieldComponent = ({ label, ...rest }) => (
<TextField {...rest} label={label} />
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one weird part that I need TS advice on. Instead of directly assigning this like

ConfirmationCode: TextFieldComponent = TextField`

I had to separate out label to go around the error label is required but is optional in TextFieldComponent. I wanted to keep label optional because it's a UI prop and IMO shouldn't be required for override components.

Copy link
Contributor

@joebuono joebuono Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried experimenting with Omit and adding default params, but I couldn't get it to work. I think the way you did it is fine. Maybe @calebpollman has an idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern with this approach is that a future maintainer might be confused if they were to attempt to update ConfirmationCode. Tbh not sure if i feel that we need to make label optional since requiring it is somewhat of a guard to ensure accessibility if i remember correctly. Also should this be ConfirmationCodeField?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair.

@wlee221 wlee221 temporarily deployed to ci December 7, 2022 19:52 — with GitHub Actions Inactive
@wlee221 wlee221 temporarily deployed to ci December 7, 2022 19:52 — with GitHub Actions Inactive
@wlee221 wlee221 temporarily deployed to ci December 7, 2022 19:52 — with GitHub Actions Inactive
@wlee221 wlee221 temporarily deployed to ci December 7, 2022 19:52 — with GitHub Actions Inactive
@@ -1,4 +1,5 @@
export enum ComponentClassName {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but enum types should ideally be included in types files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e5c9ddd + ecddcda

Comment on lines 16 to 18
export const SecretKeyQRCode: ImageComponent = Image;

export const CopySecretKey: ButtonComponent = Button;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of aligning the names of these closer to their primitives? Example:

const QRCodeImage;
const CopyButton;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, 7d5fba3

Comment on lines 12 to 14
export const ConfirmationCode: TextFieldComponent = ({ label, ...rest }) => (
<TextField {...rest} label={label} />
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern with this approach is that a future maintainer might be confused if they were to attempt to update ConfirmationCode. Tbh not sure if i feel that we need to make label optional since requiring it is somewhat of a guard to ensure accessibility if i remember correctly. Also should this be ConfirmationCodeField?

@@ -0,0 +1,5 @@
const QR_CODE_SIZE = '228px';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does hard coding work well with mobile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it with chrome + its mobile views, it worked okay:

Screen Shot 2022-12-07 at 3 50 57 PM

(I took the hardcode width from Authenticator)

I'm open to improvement ideas tho. I'll play around with it too!

);

React.useEffect(() => {
if (user && !hasInit.current) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we discussed this in the past, but can we just look at whether totpSecret is null here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user has to be there because user is initially null. I think I introduced hasInit because of some remounting issue with parent component.

Let me try using !totpSecret check again. If it turns out to be problematic later when we use this component in ConfigureMFA, we can revert it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in f658ad2


setVerifyTotpStatus({ isVerifying: false, errorMessage: null });

onSuccess?.(); // notify success to the parent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we can remove the comments here an on line 102 since onSuccess and onError are optional props and potentially custom callbacks (if i understand correctly)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3b319b1

navigator.clipboard.writeText(totpSecret.secretKey);
}, [totpSecret]);

/* Return null if Auth.getCurrentAuthenticatedUser is still in progress */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prefer inline syntax for comments that do not benefit from intellisense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3b319b1

onSuccess,
onError,
}: ConfigureTOTPProps): JSX.Element | null {
const [formValues, setFormValues] = React.useState<FormValues>({ code: '' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we plan to add more keys to formValues in the immediate future that this can be simplified to:

const [confirmationCode, setConfirmationCode] = React.useState('');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7d340ca

@wlee221 wlee221 requested a review from calebpollman December 8, 2022 00:33
@wlee221 wlee221 temporarily deployed to ci December 8, 2022 00:52 — with GitHub Actions Inactive
@wlee221 wlee221 temporarily deployed to ci December 8, 2022 00:52 — with GitHub Actions Inactive
@wlee221 wlee221 temporarily deployed to ci December 8, 2022 00:52 — with GitHub Actions Inactive
@wlee221 wlee221 temporarily deployed to ci December 8, 2022 00:52 — with GitHub Actions Inactive
@wlee221 wlee221 merged commit 159cfd6 into account-settings/main Dec 16, 2022
@wlee221 wlee221 deleted the account-settings/revert-revert-configure-totp branch December 16, 2022 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants