| 1 |
import { useState } from 'react' |
| 2 |
import FormErrors from '../components/FormErrors' |
| 3 |
import { signUpByPasskey } from '../lib/allauth' |
| 4 |
import { Link } from 'react-router-dom' |
| 5 |
import Button from '../components/Button' |
| 6 |
|
| 7 |
export default function Signup () { |
| 8 |
const [email, setEmail] = useState('') |
| 9 |
const [response, setResponse] = useState({ fetching: false, content: null }) |
| 10 |
|
| 11 |
function submit () { |
| 12 |
setResponse({ ...response, fetching: true }) |
| 13 |
signUpByPasskey({ email }).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 |
|
| 23 |
return ( |
| 24 |
<div> |
| 25 |
<h1>Passkey Sign Up</h1> |
| 26 |
<p> |
| 27 |
Already have an account? <Link to='/account/login'>Login here.</Link> |
| 28 |
</p> |
| 29 |
|
| 30 |
<FormErrors errors={response.content?.errors} /> |
| 31 |
|
| 32 |
<div><label>Email <input value={email} onChange={(e) => setEmail(e.target.value)} type='email' required /></label> |
| 33 |
<FormErrors param='email' errors={response.content?.errors} /> |
| 34 |
</div> |
| 35 |
<Button disabled={response.fetching} onClick={() => submit()}>Sign Up</Button> |
| 36 |
<a href='/account/signup'>Sign up using a password</a> |
| 37 |
</div> |
| 38 |
) |
| 39 |
} |