| 1 |
import { useState } from 'react' |
| 2 |
import FormErrors from '../components/FormErrors' |
| 3 |
import { mfaReauthenticate } from '../lib/allauth' |
| 4 |
import ReauthenticateFlow from '../account/ReauthenticateFlow' |
| 5 |
import Button from '../components/Button' |
| 6 |
|
| 7 |
export default function ReauthenticateCode (props) { |
| 8 |
const [code, setCode] = useState('') |
| 9 |
const [response, setResponse] = useState({ fetching: false, content: null }) |
| 10 |
|
| 11 |
function submit () { |
| 12 |
setResponse({ ...response, fetching: true }) |
| 13 |
mfaReauthenticate(code).then((content) => { |
| 14 |
setResponse((r) => { return { ...r, content } }) |
| 15 |
}).catch((e) => { |
| 16 |
console.error(e) |
| 17 |
window.alert(e) |
| 18 |
}).then(() => { |
| 19 |
setResponse((r) => { return { ...r, fetching: false } }) |
| 20 |
}) |
| 21 |
} |
| 22 |
return ( |
| 23 |
<ReauthenticateFlow> |
| 24 |
{props.children} |
| 25 |
|
| 26 |
<FormErrors errors={response.content?.errors} /> |
| 27 |
|
| 28 |
<div><label>Code: <input value={code} onChange={(e) => setCode(e.target.value)} type='text' required /></label> |
| 29 |
<FormErrors param='code' errors={response.content?.errors} /> |
| 30 |
</div> |
| 31 |
<Button disabled={response.fetching} onClick={() => submit()}>Confirm</Button> |
| 32 |
</ReauthenticateFlow> |
| 33 |
) |
| 34 |
} |