Automatically update the user data when 2FA is enabled
This commit is contained in:
parent
eb39826f46
commit
2a653cdd8d
2 changed files with 16 additions and 23 deletions
|
@ -20,7 +20,7 @@ export default () => {
|
||||||
</div>
|
</div>
|
||||||
:
|
:
|
||||||
<div>
|
<div>
|
||||||
<SetupTwoFactorModal visible={visible} onDismissed={() => setVisible(false)}/>
|
{visible && <SetupTwoFactorModal visible={visible} onDismissed={() => setVisible(false)}/>}
|
||||||
<p className={'text-sm'}>
|
<p className={'text-sm'}>
|
||||||
You do not currently have two-factor authentication enabled on your account. Click
|
You do not currently have two-factor authentication enabled on your account. Click
|
||||||
the button below to begin configuring it.
|
the button below to begin configuring it.
|
||||||
|
|
|
@ -14,29 +14,28 @@ interface Values {
|
||||||
code: string;
|
code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({ visible, onDismissed }: RequiredModalProps) => {
|
export default ({ ...props }: RequiredModalProps) => {
|
||||||
const [ token, setToken ] = useState('');
|
const [ token, setToken ] = useState('');
|
||||||
const [ loading, setLoading ] = useState(true);
|
const [ loading, setLoading ] = useState(true);
|
||||||
|
|
||||||
|
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
|
||||||
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!visible) {
|
|
||||||
clearFlashes('account:two-factor');
|
clearFlashes('account:two-factor');
|
||||||
getTwoFactorTokenUrl()
|
getTwoFactorTokenUrl()
|
||||||
.then(setToken)
|
.then(setToken)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
}
|
}, []);
|
||||||
}, [ visible ]);
|
|
||||||
|
|
||||||
const submit = ({ code }: Values, { resetForm, setSubmitting }: FormikActions<Values>) => {
|
const submit = ({ code }: Values, { setSubmitting }: FormikActions<Values>) => {
|
||||||
clearFlashes('account:two-factor');
|
clearFlashes('account:two-factor');
|
||||||
enableAccountTwoFactor(code)
|
enableAccountTwoFactor(code)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resetForm();
|
updateUserData({ useTotp: true });
|
||||||
setToken('');
|
props.onDismissed();
|
||||||
setLoading(true);
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -56,15 +55,9 @@ export default ({ visible, onDismissed }: RequiredModalProps) => {
|
||||||
.matches(/^(\d){6}$/, 'Authenticator code must be 6 digits.'),
|
.matches(/^(\d){6}$/, 'Authenticator code must be 6 digits.'),
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{({ isSubmitting, isValid, resetForm }) => (
|
{({ isSubmitting, isValid }) => (
|
||||||
<Modal
|
<Modal
|
||||||
visible={visible}
|
{...props}
|
||||||
onDismissed={() => {
|
|
||||||
resetForm();
|
|
||||||
setToken('');
|
|
||||||
setLoading(true);
|
|
||||||
onDismissed();
|
|
||||||
}}
|
|
||||||
dismissable={!isSubmitting}
|
dismissable={!isSubmitting}
|
||||||
showSpinnerOverlay={loading || isSubmitting}
|
showSpinnerOverlay={loading || isSubmitting}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue