Debian Codegraph @

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

raw
1 import { Link, useLoaderData } from 'react-router-dom'
2
3 import * as allauth from '../lib/allauth'
4
5 export async function loader ({ params }) {
6 const resp = await allauth.getAuthenticators()
7 return { authenticators: resp.data }
8 }
9
10 export default function MFAOverview (props) {
11 const { authenticators } = useLoaderData()
12 const totp = authenticators.find(authenticator => authenticator.type === allauth.AuthenticatorType.TOTP)
13 const webauthn = authenticators.filter(authenticator => authenticator.type === allauth.AuthenticatorType.WEBAUTHN)
14 const recoveryCodes = authenticators.find(authenticator => authenticator.type === allauth.AuthenticatorType.RECOVERY_CODES)
15 return (
16 <section>
17 <h1>Two-Factor Authentication</h1>
18
19 <h2>Authenticator App</h2>
20
21 {totp
22 ? <><p>
23 Authentication using an authenticator app is active.
24 </p>
25 <Link to='/account/2fa/totp/deactivate'>Deactivate</Link>
26 </>
27 : <><p>An authenticator app is not active..</p>
28 <Link to='/account/2fa/totp/activate'>Activate</Link>
29 </>}
30
31 <h2>Security Keys</h2>
32
33 {webauthn.length
34 ? <><p>You have added {webauthn.length} security keys.</p>
35 <Link to='/account/2fa/webauthn'>Manage</Link>
36 </>
37 : <><p>No security keys have been added.</p>
38 <Link to='/account/2fa/webauthn/add'>Add</Link>
39 </>}
40
41 <h2>Recovery Codes</h2>
42
43 {!recoveryCodes
44 ? <><p>No recovery codes set up.</p>
45 <Link to='/account/2fa/recovery-codes/generate'>Generate</Link>
46 </>
47 : <><p>There are {recoveryCodes.unused_code_count} out of {recoveryCodes.total_code_count} recovery codes available.</p>
48 <Link to='/account/2fa/recovery-codes'>View</Link>
49 <Link to='/account/2fa/recovery-codes/generate'>Regenerate</Link>
50 </>}
51 </section>
52 )
53 }