| 1 |
import { Link, useLocation } from 'react-router-dom' |
| 2 |
import { pathForFlow } from '../auth' |
| 3 |
import { Flows, AuthenticatorType } from '../lib/allauth' |
| 4 |
|
| 5 |
const flowLabels = {} |
| 6 |
flowLabels[Flows.REAUTHENTICATE] = 'Use your password' |
| 7 |
flowLabels[`${Flows.MFA_REAUTHENTICATE}:${AuthenticatorType.TOTP}`] = 'Use your authenticator app' |
| 8 |
flowLabels[`${Flows.MFA_REAUTHENTICATE}:${AuthenticatorType.RECOVERY_CODES}`] = 'Use a recovery code' |
| 9 |
flowLabels[`${Flows.MFA_REAUTHENTICATE}:${AuthenticatorType.WEBAUTHN}`] = 'Use security key' |
| 10 |
|
| 11 |
function flowsToMethods (flows) { |
| 12 |
const methods = [] |
| 13 |
flows.forEach(flow => { |
| 14 |
if (flow.id === Flows.MFA_REAUTHENTICATE) { |
| 15 |
flow.types.forEach(typ => { |
| 16 |
const id = `${flow.id}:${typ}` |
| 17 |
methods.push({ |
| 18 |
label: flowLabels[id], |
| 19 |
id, |
| 20 |
path: pathForFlow(flow, typ) |
| 21 |
}) |
| 22 |
}) |
| 23 |
} else { |
| 24 |
methods.push({ |
| 25 |
label: flowLabels[flow.id] || flow.id, |
| 26 |
id: flow.id, |
| 27 |
path: pathForFlow(flow) |
| 28 |
}) |
| 29 |
} |
| 30 |
}) |
| 31 |
return methods |
| 32 |
} |
| 33 |
|
| 34 |
export default function ReauthenticateFlow (props) { |
| 35 |
const location = useLocation() |
| 36 |
const methods = flowsToMethods(location.state.reauth.data.flows) |
| 37 |
|
| 38 |
return ( |
| 39 |
<div> |
| 40 |
<h1>Confirm Access</h1> |
| 41 |
<p> |
| 42 |
Please reauthenticate to safeguard your account. |
| 43 |
</p> |
| 44 |
{props.children} |
| 45 |
|
| 46 |
{methods.length > 1 |
| 47 |
? <><h2>Alternative Options</h2> |
| 48 |
<ul> |
| 49 |
{methods.filter(method => method.id !== props.method).map(method => { |
| 50 |
return ( |
| 51 |
<li key={method.id}> |
| 52 |
<Link replace state={location.state} to={method.path + location.search}>{method.label}</Link> |
| 53 |
</li> |
| 54 |
) |
| 55 |
})} |
| 56 |
</ul> |
| 57 |
</> |
| 58 |
: null} |
| 59 |
</div> |
| 60 |
|
| 61 |
) |
| 62 |
} |