Debian Codegraph @

examples/react-spa/frontend/src/mfa/Trust.js

raw
1 import { useState } from 'react'
2 import AuthenticateCode from './AuthenticateCode'
3 import { AuthenticatorType } from '../lib/allauth'
4 import { useAuthInfo } from '../auth/hooks'
5 import * as allauth from '../lib/allauth'
6 import { Navigate } from 'react-router-dom'
7 import Button from'../components/Button'
8
9 export default function Trust (props) {
10 const [response, setResponse] = useState({ fetching: false, content: null })
11 const authInfo = useAuthInfo()
12
13 if (authInfo?.pendingFlow?.id !== allauth.Flows.MFA_TRUST) {
14 return <Navigate to='/' />
15 }
16
17 function submit (trust) {
18 setResponse({ ...response, fetching: true })
19 allauth.mfaTrust(trust).then((content) => {
20 setResponse((r) => { return { ...r, content } })
21 }).catch((e) => {
22 console.error(e)
23 window.alert(e)
24 }).then(() => {
25 setResponse((r) => { return { ...r, fetching: false } })
26 })
27 }
28 return (
29 <section>
30 <h1>Trust this Browser?</h1>
31 <p>If you choose to trust this browser, you will not be asked for a verification code the next time you sign in.</p>
32 <Button onClick={() => submit(false)}>Don't Trust</Button>
33 <Button onClick={() => submit(true)}>Trust</Button>
34 </section>
35 )
36 }