From 2a653cdd8d5fa3e548e4b7f281160df58c6a8cd7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 22 Dec 2019 20:23:43 -0800 Subject: [PATCH] Automatically update the user data when 2FA is enabled --- .../forms/ConfigureTwoFactorForm.tsx | 2 +- .../dashboard/forms/SetupTwoFactorModal.tsx | 37 ++++++++----------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/resources/scripts/components/dashboard/forms/ConfigureTwoFactorForm.tsx b/resources/scripts/components/dashboard/forms/ConfigureTwoFactorForm.tsx index 5aef3bce9..7f8e502ab 100644 --- a/resources/scripts/components/dashboard/forms/ConfigureTwoFactorForm.tsx +++ b/resources/scripts/components/dashboard/forms/ConfigureTwoFactorForm.tsx @@ -20,7 +20,7 @@ export default () => { :
- setVisible(false)}/> + {visible && setVisible(false)}/>}

You do not currently have two-factor authentication enabled on your account. Click the button below to begin configuring it. diff --git a/resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx b/resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx index 6151094bb..5a9439ad5 100644 --- a/resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx +++ b/resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx @@ -14,29 +14,28 @@ interface Values { code: string; } -export default ({ visible, onDismissed }: RequiredModalProps) => { +export default ({ ...props }: RequiredModalProps) => { const [ token, setToken ] = useState(''); const [ loading, setLoading ] = useState(true); + + const updateUserData = useStoreActions((actions: Actions) => actions.user.updateUserData); const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); useEffect(() => { - if (!visible) { - clearFlashes('account:two-factor'); - getTwoFactorTokenUrl() - .then(setToken) - .catch(error => { - console.error(error); - }); - } - }, [ visible ]); + clearFlashes('account:two-factor'); + getTwoFactorTokenUrl() + .then(setToken) + .catch(error => { + console.error(error); + }); + }, []); - const submit = ({ code }: Values, { resetForm, setSubmitting }: FormikActions) => { + const submit = ({ code }: Values, { setSubmitting }: FormikActions) => { clearFlashes('account:two-factor'); enableAccountTwoFactor(code) .then(() => { - resetForm(); - setToken(''); - setLoading(true); + updateUserData({ useTotp: true }); + props.onDismissed(); }) .catch(error => { console.error(error); @@ -56,15 +55,9 @@ export default ({ visible, onDismissed }: RequiredModalProps) => { .matches(/^(\d){6}$/, 'Authenticator code must be 6 digits.'), })} > - {({ isSubmitting, isValid, resetForm }) => ( + {({ isSubmitting, isValid }) => ( { - resetForm(); - setToken(''); - setLoading(true); - onDismissed(); - }} + {...props} dismissable={!isSubmitting} showSpinnerOverlay={loading || isSubmitting} >