Place the SDK container inside your component (e.g., AuthyoLogin.js):
<div id="authyo-2fasdk"></div>
Use useEffect to inject the SDK into the DOM:
useEffect(() => {
const script = document.createElement("script");
script.src = "https://app.authyo.io/js/v1/auth-2fasdk.js";
script.setAttribute("data-appkey", "YOUR_APP_KEY");
script.setAttribute("data-emailid", "YOUR_EMAIL");
script.async = true;
document.body.appendChild(script);
}, []);
Bind the response handler using window.authyoResponse:
useEffect(() => {
window.authyoResponse = (response) => {
if (response.success) {
console.log("✅ User Verified:", response.data);
} else {
console.error("❌ Login Failed:", response.message);
}
};
}, []);
import React, { useEffect } from "react";const AuthyoLogin = () => {
useEffect(() => {
const script = document.createElement("script");
script.src = "https://app.authyo.io/js/v1/auth-2fasdk.js";
script.setAttribute("data-appkey", "123456-app-key-xyz");
script.setAttribute("data-emailid", "abc@xyz.com");
script.async = true;
document.body.appendChild(script);window.authyoResponse = (response) => {
if (response.success) {
console.log("✅ Verified:", response.data);
} else {
console.log("❌ Failed:", response.message);
}
};
}, []);return <div id="authyo-2fasdk"></div>;
};
export default AuthyoLogin;
{
"success": true,
"IsTOtpVerified": false,
"message": "ok"
}
{
"success": true,
"message": "qrcode generated successfully",
"QRCoder": "data:image/png;base64,....",
"maskId": "optional"
}
{ "success": true, "message": "verified" }
{ "success": true, "message": "2FA disabled" }
| Problem | Fix |
|---|---|
| Widget not loading | Ensure #authyo-2fasdk div exists before the script |
| Blank screen | Ensure valid data-appkey and data-emailid is used |
| No response callback | Implement window.authyoResponse |
| Styling off | Check App Key design settings in dashboard |