import React, { useEffect, useState } from 'react'; import tw from 'twin.macro'; import webauthnChallenge from '@/api/account/webauthn/webauthnChallenge'; import { DivContainer as LoginFormContainer } from '@/components/auth/LoginFormContainer'; import useFlash from '@/plugins/useFlash'; import { useLocation } from 'react-router'; import { Link, useHistory } from 'react-router-dom'; import Spinner from '@/components/elements/Spinner'; import Button from '@/components/elements/Button'; interface LocationParams { token: string; publicKey: any; hasTotp: boolean; } const LoginKeyCheckpointContainer = () => { const history = useHistory(); const location = useLocation(); const { clearAndAddHttpError } = useFlash(); const [ challenging, setChallenging ] = useState(false); const switchToCode = () => { history.replace('/auth/login/checkpoint', { ...location.state, recovery: false }); }; const switchToRecovery = () => { history.replace('/auth/login/checkpoint', { ...location.state, recovery: true }); }; const doChallenge = () => { setChallenging(true); webauthnChallenge(location.state.token, location.state.publicKey) .then(response => { if (!response.complete) { return; } // @ts-ignore window.location = response.intended || '/'; }) .catch(error => { clearAndAddHttpError({ error }); console.error(error); setChallenging(false); }); }; useEffect(() => { doChallenge(); }, []); return (

Attempting challenge...

{challenging ? : }
switchToCode()} > Use two-factor token
switchToRecovery()} > I've Lost My Device
Return to Login
); }; export default () => { const history = useHistory(); const location = useLocation(); if (!location.state?.token) { history.replace('/auth/login'); return null; } return ; };