Authyo Docs
  1. 2FA SDK
Authyo Docs
  • 🐶 Walk through Authyo
  • Error Codes
  • About Pricing
  • APIs
    • Send OTP
      GET
    • Send OTP
      POST
    • Verify OTP
      GET
    • Verify Token
      POST
    • Revoke User Session
      POST
  • Web SDKs
    • JavaScript
    • PHP
    • AngularJS Examples
    • TypeScript Examples
    • React JS
    • Vue JS Examples
  • 2FA SDK
    • JavaScript
    • AngularJS Examples
    • PHP
    • React JS
    • TypeScript Examples
    • Vue JS Examples
  • Native/Mobile SDKs
    • Flutter
  • Integration
    • Google Sheet
    • Firebase
  • Session Management
    • Introductions
    • JWT Token
  1. 2FA SDK

React JS

JavaScript SDK

React Integration

Step 1: Add the Container

Place the SDK container inside your component (e.g., AuthyoLogin.js):

<div id="authyo-2fasdk"></div>

Step 2: Load the SDK Script Dynamically

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);
}, []);

Step 3: Handle Authyo Response

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);
    }
  };
}, []);

Example: Complete React Component

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;

Two Factor Authenticate – Requests & Responses

1) AuthState
Response
{
  "success": true,
  "IsTOtpVerified": false,
  "message": "ok"
}
    
2) Enable 2FA
Response
{
  "success": true,
  "message": "qrcode generated successfully",
  "QRCoder": "data:image/png;base64,....",
  "maskId": "optional"
}
    
3) Verify Otp
Response
{ "success": true, "message": "verified" }
    
4) Disable 2FA
Response
{ "success": true, "message": "2FA disabled" }
    

Troubleshooting

ProblemFix
Widget not loadingEnsure #authyo-2fasdk div exists before the script
Blank screenEnsure valid data-appkey and data-emailid is used
No response callbackImplement window.authyoResponse
Styling offCheck App Key design settings in dashboard
Modified at 2025-10-06 13:17:12
Previous
PHP
Next
TypeScript Examples
Built with