import React, { useCallback, useState, useEffect } from 'react'; import api from '../script/axiosApi'; // function DoubleAuth() { // // const enabled = await api.get("/2fa"); // // const response = await api.get("/2fa"); // // const enabled = response.data; // // console.log(`enable= ${enabled.data}`) // // const enabled = 0; // let enabled; // useEffect(() => { // async function get2fa() // { // const response = await api.get("/2fa"); // const enabled = response.data; // console.log(`enable= ${enabled.data}`) // } // // const enabled = 0; // }, []) // useEffect(() => { // async function get2fa() // { // api.get('/api/QRcode', { responseType: 'blob' }) // .then(response => { // const reader = new FileReader(); // reader.onloadend = () => { // setImageSrc(reader.result); // }; // reader.readAsDataURL(response.data); // }) // .catch(error => { // console.error(error); // }); // } }, []); // // const [verificationCode, setVerificationCode] = useState(''); // // const [invalidCode, setInvalidCode] = useState(false); // const handleSubmit = () => { // // async (e) => { // // e.preventDefault(); // // const result = await verifyOtp(verificationCode); // // if (result) return (window.location = '/'); // // setInvalidCode(true); // // }, // // [verificationCode] // }; // let sourceCode // if (!enabled) // { // api.get('/QRcode') // .then(response => { // sourceCode = response.data; // console.log(sourceCode); // }) // .catch(error => { // console.error(error); // }); // } // return ( //
// {!enabled && ( //
//

Scan the QR code on your authenticator app

// //
// )} //
// {/* setVerificationCode(e.target.value)} // /> */} // // {/* {invalidCode &&

Invalid verification code

} */} //
//
// ); // } // import { toFileStream } from 'qrcode'; const DoubleAuth = () => { const [imageSrc, setImageSrc] = useState(''); useEffect(() => { async function getCode(){ await api.get('/QRcode', { responseType: 'blob' }) .then(response => { const reader = new FileReader(); reader.onloadend = () => { setImageSrc(reader.result); }; reader.readAsDataURL(response.data); }) .catch(error => { console.error(error); }); } getCode(); }, []); // return ( //
// {imageSrc && QR Code} //
// ); // return (

Scan the QR code on your authenticator app

{imageSrc && QR Code}
{/*
*/}
); }; export default DoubleAuth;