Debian Codegraph @

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

raw
1 import { useState } from 'react'
2 import * as allauth from '../lib/allauth'
3 import { Navigate } from 'react-router-dom'
4 import Button from '../components/Button'
5
6 export default function DeactivateTOTP (props) {
7 const [response, setResponse] = useState({ fetching: false, content: null })
8
9 function submit () {
10 setResponse({ ...response, fetching: true })
11 allauth.deactivateTOTPAuthenticator().then((content) => {
12 setResponse((r) => { return { ...r, content } })
13 }).catch((e) => {
14 console.error(e)
15 window.alert(e)
16 }).then(() => {
17 setResponse((r) => { return { ...r, fetching: false } })
18 })
19 }
20 if (response.content?.status === 200) {
21 return <Navigate to='/account/2fa' />
22 }
23 return (
24 <section>
25 <h1>Deactivate Authenticator App</h1>
26
27 <p>You are about to deactivate authenticator app based authentication. Are you sure?</p>
28
29 <Button onClick={() => submit()}>Deactivate</Button>
30 </section>
31 )
32 }