chore: use token input on enable 2fa

This commit is contained in:
Ephraim Atta-Duncan
2024-02-16 21:20:16 +00:00
parent 94eee8b913
commit 918e9ddc0b

View File

@ -130,6 +130,10 @@ export const EnableAuthenticatorAppDialog = ({
return enabled2fa; return enabled2fa;
} catch (_err) { } catch (_err) {
enableTwoFactorAuthenticationForm.setError('token', {
message: 'Unable to setup two-factor authentication',
});
toast({ toast({
title: 'Unable to setup two-factor authentication', title: 'Unable to setup two-factor authentication',
description: description:
@ -251,15 +255,19 @@ export const EnableAuthenticatorAppDialog = ({
<PinInput <PinInput
id="enable-2fa-pin-input" id="enable-2fa-pin-input"
state={state} state={state}
onSubmit={({ code, input }) => { onSubmit={async ({ code, input }) => {
console.log(code);
if (code.length === 6) { if (code.length === 6) {
setState('loading'); setState('loading');
enableTwoFactorAuthenticationForm.setValue('token', code);
void onEnableTwoFactorAuthenticationFormSubmit({ token: code }).then( await enableTwoFactorAuthenticationForm.handleSubmit(
(success) => { onEnableTwoFactorAuthenticationFormSubmit,
if (success) { )();
if (
enableTwoFactorAuthenticationForm.formState.isSubmitted &&
!enableTwoFactorAuthenticationForm.formState.errors.totpCode
) {
setState('success'); setState('success');
return; return;
} }
@ -272,19 +280,16 @@ export const EnableAuthenticatorAppDialog = ({
input.dispatchEvent(new Event('input')); input.dispatchEvent(new Event('input'));
input.focus(); input.focus();
}, 500); }, 500);
},
);
} }
}} }}
autoFocus autoFocus
/> />
</FormControl> </FormControl>
<FormMessage />
</FormItem> </FormItem>
)} )}
/> />
{/* <DialogFooter> <DialogFooter>
<Button type="button" variant="secondary" onClick={() => onOpenChange(false)}> <Button type="button" variant="secondary" onClick={() => onOpenChange(false)}>
Cancel Cancel
</Button> </Button>
@ -292,7 +297,7 @@ export const EnableAuthenticatorAppDialog = ({
<Button type="submit" loading={isEnableTwoFactorAuthenticationSubmitting}> <Button type="submit" loading={isEnableTwoFactorAuthenticationSubmitting}>
Enable 2FA Enable 2FA
</Button> </Button>
</DialogFooter> */} </DialogFooter>
</form> </form>
</Form> </Form>
)) ))