Skip to content

Commit 2a653cd

Browse files
committed
Automatically update the user data when 2FA is enabled
1 parent eb39826 commit 2a653cd

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

resources/scripts/components/dashboard/forms/ConfigureTwoFactorForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default () => {
2020
</div>
2121
:
2222
<div>
23-
<SetupTwoFactorModal visible={visible} onDismissed={() => setVisible(false)}/>
23+
{visible && <SetupTwoFactorModal visible={visible} onDismissed={() => setVisible(false)}/>}
2424
<p className={'text-sm'}>
2525
You do not currently have two-factor authentication enabled on your account. Click
2626
the button below to begin configuring it.

resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,28 @@ interface Values {
1414
code: string;
1515
}
1616

17-
export default ({ visible, onDismissed }: RequiredModalProps) => {
17+
export default ({ ...props }: RequiredModalProps) => {
1818
const [ token, setToken ] = useState('');
1919
const [ loading, setLoading ] = useState(true);
20+
21+
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
2022
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
2123

2224
useEffect(() => {
23-
if (!visible) {
24-
clearFlashes('account:two-factor');
25-
getTwoFactorTokenUrl()
26-
.then(setToken)
27-
.catch(error => {
28-
console.error(error);
29-
});
30-
}
31-
}, [ visible ]);
25+
clearFlashes('account:two-factor');
26+
getTwoFactorTokenUrl()
27+
.then(setToken)
28+
.catch(error => {
29+
console.error(error);
30+
});
31+
}, []);
3232

33-
const submit = ({ code }: Values, { resetForm, setSubmitting }: FormikActions<Values>) => {
33+
const submit = ({ code }: Values, { setSubmitting }: FormikActions<Values>) => {
3434
clearFlashes('account:two-factor');
3535
enableAccountTwoFactor(code)
3636
.then(() => {
37-
resetForm();
38-
setToken('');
39-
setLoading(true);
37+
updateUserData({ useTotp: true });
38+
props.onDismissed();
4039
})
4140
.catch(error => {
4241
console.error(error);
@@ -56,15 +55,9 @@ export default ({ visible, onDismissed }: RequiredModalProps) => {
5655
.matches(/^(\d){6}$/, 'Authenticator code must be 6 digits.'),
5756
})}
5857
>
59-
{({ isSubmitting, isValid, resetForm }) => (
58+
{({ isSubmitting, isValid }) => (
6059
<Modal
61-
visible={visible}
62-
onDismissed={() => {
63-
resetForm();
64-
setToken('');
65-
setLoading(true);
66-
onDismissed();
67-
}}
60+
{...props}
6861
dismissable={!isSubmitting}
6962
showSpinnerOverlay={loading || isSubmitting}
7063
>

0 commit comments

Comments
 (0)