Debian Codegraph @

examples/react-spa/frontend/src/account/Reauthenticate.js

raw
1 import { useState } from 'react'
2 import FormErrors from '../components/FormErrors'
3 import { reauthenticate, Flows } from '../lib/allauth'
4 import ReauthenticateFlow from './ReauthenticateFlow'
5 import Button from '../components/Button'
6
7 export default function Reauthenticate () {
8 const [password, setPassword] = useState('')
9 const [response, setResponse] = useState({ fetching: false, content: null })
10
11 function submit () {
12 setResponse({ ...response, fetching: true })
13 reauthenticate({ password }).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 flow={Flows.REAUTHENTICATE}>
24 <p>Enter your password:</p>
25
26 <FormErrors errors={response.content?.errors} />
27
28 <div><label>Password: <input value={password} onChange={(e) => setPassword(e.target.value)} type='password' required /></label>
29 <FormErrors param='password' errors={response.content?.errors} />
30 </div>
31 <Button disabled={response.fetching} onClick={() => submit()}>Confirm</Button>
32 </ReauthenticateFlow>
33 )
34 }