import React from 'react' ; import cfg from 'teleport/config' ; import auth from 'teleport/services/auth' ; import useAttempt from 'shared/hooks/useAttemptNext' ; export default function useReAuthenticate ( { onAuthenticated , onClose } ) { const { attempt , setAttempt , handleError } = useAttempt ( '' ) ; function submitWithTotp ( secondFactorToken ) { setAttempt ( { status : 'processing' } ) ; auth . createPrivilegeTokenWithTotp ( secondFactorToken ) . then ( onAuthenticated ) . catch ( handleError ) ; } function submitWithU2f ( ) { setAttempt ( { status : 'processing' } ) ; auth . createPrivilegeTokenWithU2f ( ) . then ( onAuthenticated ) . catch ( handleError ) ; } function submitWithWebauthn ( ) { setAttempt ( { status : 'processing' } ) ; auth . createPrivilegeTokenWithWebauthn ( ) . then ( onAuthenticated ) . catch ( handleError ) ; } function clearAttempt ( ) { setAttempt ( { status : '' } ) ; } return { attempt , clearAttempt , submitWithTotp , submitWithU2f , submitWithWebauthn , auth2faType : cfg . getAuth2faType ( ) , preferredMfaType : cfg . getPreferredMfaType ( ) , onClose , } ; } export type Props = { onAuthenticated : React . Dispatch < React . SetStateAction < string > > ; onClose : ( ) => void ; } ; export type State = ReturnType < typeof useReAuthenticate > ;