-
Notifications
You must be signed in to change notification settings - Fork 308
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
feat(account-settings): Add back SetupTOTP
#3149
Conversation
|
export const ConfirmationCode: TextFieldComponent = ({ label, ...rest }) => ( | ||
<TextField {...rest} label={label} /> | ||
); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1,4 +1,5 @@ | |||
export enum ComponentClassName { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/react/src/components/AccountSettings/SetupTOTP/types.ts
Outdated
Show resolved
Hide resolved
export const SecretKeyQRCode: ImageComponent = Image; | ||
|
||
export const CopySecretKey: ButtonComponent = Button; |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, 7d5fba3
export const ConfirmationCode: TextFieldComponent = ({ label, ...rest }) => ( | ||
<TextField {...rest} label={label} /> | ||
); |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/react/src/components/AccountSettings/SetupTOTP/SetupTOTP.tsx
Outdated
Show resolved
Hide resolved
); | ||
|
||
React.useEffect(() => { | ||
if (user && !hasInit.current) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: '' }); |
There was a problem hiding this comment.
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('');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 7d340ca
Co-authored-by: Caleb Pollman <cpollman@amazon.com>
…b.com:aws-amplify/amplify-ui into account-settings/revert-revert-configure-totp
…OTP.tsx Co-authored-by: Caleb Pollman <cpollman@amazon.com>
…b.com:aws-amplify/amplify-ui into account-settings/revert-revert-configure-totp
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:ConfigureTOTP
->AccountSettings.SetupTOTP
Issue #, if available
Description of how you validated changes
Unit tests
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.