feat: submit 2FA code upon pressing enter
This commit is contained in:
parent
6023895547
commit
1b81da35d2
5 changed files with 100 additions and 64 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import { useMutation, useLazyQuery } from '@apollo/react-hooks'
|
import { useMutation, useLazyQuery } from '@apollo/react-hooks'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import base64 from 'base-64'
|
import base64 from 'base-64'
|
||||||
|
import { Form, Formik } from 'formik'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import React, { useContext, useState } from 'react'
|
import React, { useContext, useState } from 'react'
|
||||||
import { useHistory } from 'react-router-dom'
|
import { useHistory } from 'react-router-dom'
|
||||||
|
|
@ -120,6 +121,9 @@ const Input2FAState = ({ state, dispatch }) => {
|
||||||
<TL1 className={classes.info}>
|
<TL1 className={classes.info}>
|
||||||
Enter your two-factor authentication code
|
Enter your two-factor authentication code
|
||||||
</TL1>
|
</TL1>
|
||||||
|
{/* TODO: refactor the 2FA CodeInput to properly use Formik */}
|
||||||
|
<Formik onSubmit={() => {}} initialValues={{}}>
|
||||||
|
<Form>
|
||||||
<CodeInput
|
<CodeInput
|
||||||
name="2fa"
|
name="2fa"
|
||||||
value={state.twoFAField}
|
value={state.twoFAField}
|
||||||
|
|
@ -128,6 +132,9 @@ const Input2FAState = ({ state, dispatch }) => {
|
||||||
error={invalidToken}
|
error={invalidToken}
|
||||||
shouldAutoFocus
|
shouldAutoFocus
|
||||||
/>
|
/>
|
||||||
|
<button onClick={handleSubmit} className={classes.enterButton} />
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
<div className={classes.twofaFooter}>
|
<div className={classes.twofaFooter}>
|
||||||
{errorMessage && <P className={classes.errorMessage}>{errorMessage}</P>}
|
{errorMessage && <P className={classes.errorMessage}>{errorMessage}</P>}
|
||||||
<Button onClick={handleSubmit} buttonClassName={classes.loginButton}>
|
<Button onClick={handleSubmit} buttonClassName={classes.loginButton}>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useQuery, useMutation } from '@apollo/react-hooks'
|
import { useQuery, useMutation } from '@apollo/react-hooks'
|
||||||
import { makeStyles, Grid } from '@material-ui/core'
|
import { makeStyles, Grid } from '@material-ui/core'
|
||||||
import Paper from '@material-ui/core/Paper'
|
import Paper from '@material-ui/core/Paper'
|
||||||
|
import { Form, Formik } from 'formik'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import QRCode from 'qrcode.react'
|
import QRCode from 'qrcode.react'
|
||||||
import React, { useReducer, useState } from 'react'
|
import React, { useReducer, useState } from 'react'
|
||||||
|
|
@ -101,6 +102,20 @@ const Reset2FA = () => {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (twoFAConfirmation.length !== 6) {
|
||||||
|
setInvalidToken(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
reset2FA({
|
||||||
|
variables: {
|
||||||
|
token: token,
|
||||||
|
userID: state.userID,
|
||||||
|
code: twoFAConfirmation
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
|
|
@ -152,6 +167,9 @@ const Reset2FA = () => {
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.confirm2FAInput}>
|
<div className={classes.confirm2FAInput}>
|
||||||
|
{/* TODO: refactor the 2FA CodeInput to properly use Formik */}
|
||||||
|
<Formik onSubmit={() => {}} initialValues={{}}>
|
||||||
|
<Form>
|
||||||
<CodeInput
|
<CodeInput
|
||||||
name="2fa"
|
name="2fa"
|
||||||
value={twoFAConfirmation}
|
value={twoFAConfirmation}
|
||||||
|
|
@ -160,25 +178,19 @@ const Reset2FA = () => {
|
||||||
error={invalidToken}
|
error={invalidToken}
|
||||||
shouldAutoFocus
|
shouldAutoFocus
|
||||||
/>
|
/>
|
||||||
|
<button
|
||||||
|
onClick={handleSubmit}
|
||||||
|
className={classes.enterButton}
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.twofaFooter}>
|
<div className={classes.twofaFooter}>
|
||||||
{getErrorMsg() && (
|
{getErrorMsg() && (
|
||||||
<P className={classes.errorMessage}>{getErrorMsg()}</P>
|
<P className={classes.errorMessage}>{getErrorMsg()}</P>
|
||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={handleSubmit}
|
||||||
if (twoFAConfirmation.length !== 6) {
|
|
||||||
setInvalidToken(true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
reset2FA({
|
|
||||||
variables: {
|
|
||||||
token: token,
|
|
||||||
userID: state.userID,
|
|
||||||
code: twoFAConfirmation
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
buttonClassName={classes.loginButton}>
|
buttonClassName={classes.loginButton}>
|
||||||
Done
|
Done
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useMutation, useQuery, useLazyQuery } from '@apollo/react-hooks'
|
import { useMutation, useQuery, useLazyQuery } from '@apollo/react-hooks'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import base64 from 'base-64'
|
import base64 from 'base-64'
|
||||||
|
import { Form, Formik } from 'formik'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import QRCode from 'qrcode.react'
|
import QRCode from 'qrcode.react'
|
||||||
import React, { useContext, useState } from 'react'
|
import React, { useContext, useState } from 'react'
|
||||||
|
|
@ -125,6 +126,14 @@ const Setup2FAState = ({ state, dispatch }) => {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (twoFAConfirmation.length !== 6) {
|
||||||
|
setInvalidToken(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setup2FA(mutationOptions)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
secret &&
|
secret &&
|
||||||
otpauth && (
|
otpauth && (
|
||||||
|
|
@ -159,6 +168,9 @@ const Setup2FAState = ({ state, dispatch }) => {
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.confirm2FAInput}>
|
<div className={classes.confirm2FAInput}>
|
||||||
|
{/* TODO: refactor the 2FA CodeInput to properly use Formik */}
|
||||||
|
<Formik onSubmit={() => {}} initialValues={{}}>
|
||||||
|
<Form>
|
||||||
<CodeInput
|
<CodeInput
|
||||||
name="2fa"
|
name="2fa"
|
||||||
value={twoFAConfirmation}
|
value={twoFAConfirmation}
|
||||||
|
|
@ -167,20 +179,15 @@ const Setup2FAState = ({ state, dispatch }) => {
|
||||||
error={invalidToken}
|
error={invalidToken}
|
||||||
shouldAutoFocus
|
shouldAutoFocus
|
||||||
/>
|
/>
|
||||||
|
<button onClick={handleSubmit} className={classes.enterButton} />
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.twofaFooter}>
|
<div className={classes.twofaFooter}>
|
||||||
{getErrorMsg() && (
|
{getErrorMsg() && (
|
||||||
<P className={classes.errorMessage}>{getErrorMsg()}</P>
|
<P className={classes.errorMessage}>{getErrorMsg()}</P>
|
||||||
)}
|
)}
|
||||||
<Button
|
<Button onClick={handleSubmit} buttonClassName={classes.loginButton}>
|
||||||
onClick={() => {
|
|
||||||
if (twoFAConfirmation.length !== 6) {
|
|
||||||
setInvalidToken(true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setup2FA(mutationOptions)
|
|
||||||
}}
|
|
||||||
buttonClassName={classes.loginButton}>
|
|
||||||
Done
|
Done
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,9 @@ const styles = {
|
||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
color: errorColor
|
color: errorColor
|
||||||
|
},
|
||||||
|
enterButton: {
|
||||||
|
display: 'none'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { useLazyQuery } from '@apollo/react-hooks'
|
import { useLazyQuery } from '@apollo/react-hooks'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
|
import { Form, Formik } from 'formik'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
|
|
@ -48,6 +49,14 @@ const Input2FAModal = ({ showModal, handleClose, setConfirmation }) => {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (twoFACode.length !== 6) {
|
||||||
|
setInvalidCode(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
confirm2FA({ variables: { code: twoFACode } })
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
showModal && (
|
showModal && (
|
||||||
<Modal
|
<Modal
|
||||||
|
|
@ -61,6 +70,9 @@ const Input2FAModal = ({ showModal, handleClose, setConfirmation }) => {
|
||||||
To make changes on this user, please confirm this action by entering
|
To make changes on this user, please confirm this action by entering
|
||||||
your two-factor authentication code below.
|
your two-factor authentication code below.
|
||||||
</P>
|
</P>
|
||||||
|
{/* TODO: refactor the 2FA CodeInput to properly use Formik */}
|
||||||
|
<Formik onSubmit={() => {}} initialValues={{}}>
|
||||||
|
<Form>
|
||||||
<CodeInput
|
<CodeInput
|
||||||
name="2fa"
|
name="2fa"
|
||||||
value={twoFACode}
|
value={twoFACode}
|
||||||
|
|
@ -70,19 +82,14 @@ const Input2FAModal = ({ showModal, handleClose, setConfirmation }) => {
|
||||||
containerStyle={classes.codeContainer}
|
containerStyle={classes.codeContainer}
|
||||||
shouldAutoFocus
|
shouldAutoFocus
|
||||||
/>
|
/>
|
||||||
|
<button onClick={handleSubmit} className={classes.enterButton} />
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
{getErrorMsg() && (
|
{getErrorMsg() && (
|
||||||
<P className={classes.errorMessage}>{getErrorMsg()}</P>
|
<P className={classes.errorMessage}>{getErrorMsg()}</P>
|
||||||
)}
|
)}
|
||||||
<div className={classes.footer}>
|
<div className={classes.footer}>
|
||||||
<Button
|
<Button className={classes.submit} onClick={handleSubmit}>
|
||||||
className={classes.submit}
|
|
||||||
onClick={() => {
|
|
||||||
if (twoFACode.length !== 6) {
|
|
||||||
setInvalidCode(true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
confirm2FA({ variables: { code: twoFACode } })
|
|
||||||
}}>
|
|
||||||
Confirm
|
Confirm
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue