import { useStorage } from "@tensamin/storage/context"; import { useEffect, useState } from "react"; import QRCode from "qrcode"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, Button, } from "@tensamin/ui"; export default function Page() { return (
); } // QR Code Login const generateQR = async (text: string): Promise => { try { const url = await QRCode.toDataURL(text, { errorCorrectionLevel: "H", margin: 1, color: { dark: "#000000FF", light: "#FFFFFFFF", }, }); return url; } catch (err) { console.error(err); throw err; } }; function QrCodeLogin() { const { load } = useStorage(); const [userId, setUserId] = useState(0); const [privateKey, setPrivateKey] = useState(""); const [qrCodeBase64, setQrCodeBase64] = useState( undefined, ); const [connectionString, setConnectionString] = useState(null); useEffect(() => { load("private_key").then((value) => { if (value) { setPrivateKey(value); } }); load("user_id").then((value) => { if (value) { setUserId(value); } }); load("ttp_url") .then((value) => { if (value) { const url = new URL(value); setConnectionString(`@${url.host}`); } else { setConnectionString(""); } }) .catch(() => setConnectionString("")); }, [load]); useEffect(() => { if (userId && privateKey && connectionString !== null) { generateQR( `tensamin://tu::${userId}${connectionString}::${privateKey}`, ).then(setQrCodeBase64); } }, [userId, privateKey, connectionString]); const [qrCodeVisible, setQrCodeVisible] = useState(false); return (

Login QR Code

{qrCodeBase64 && ( QR Code )} {!qrCodeVisible && ( <>
Show QR Code} /> Are you sure? Exposing this QR code is the same as sharing your .tu file. Since changing your private key is quite tedious, only do this when you're confident the key won't be compromised. Cancel setQrCodeVisible(true)}> Show QR Code } />
)}
); }