Debian Codegraph @

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

raw
1 import { Link, Navigate } from 'react-router-dom'
2 import { pathForFlow } from '../auth'
3 import { Flows, AuthenticatorType } from '../lib/allauth'
4 import { useAuthInfo } from '../auth/hooks'
5
6 const labels = {}
7 labels[AuthenticatorType.TOTP] = 'Use your authenticator app'
8 labels[AuthenticatorType.RECOVERY_CODES] = 'Use a recovery code'
9 labels[AuthenticatorType.WEBAUTHN] = 'Use security key'
10
11 export default function AuthenticateFlow (props) {
12 const authInfo = useAuthInfo()
13
14 if (authInfo?.pendingFlow?.id !== Flows.MFA_AUTHENTICATE) {
15 return <Navigate to='/' />
16 }
17 const flow = authInfo.pendingFlow
18
19 return (
20 <section>
21 <h1>Two-Factor Authentication</h1>
22 <p>
23 Your account is protected by two-factor authentication.
24 </p>
25 {props.children}
26
27 {flow.types.length > 1
28 ? <><h2>Alternative Options</h2>
29 <ul>
30 {flow.types.map(typ => {
31 return (
32 <li key={typ}>
33 <Link replace to={pathForFlow(flow, typ)}>{labels[typ]}</Link>
34 </li>
35 )
36 })}
37 </ul>
38 </>
39 : null}
40 </section>
41
42 )
43 }