Authyo Docs
  1. Web SDKs
Authyo Docs
  • 🐶 Walk through Authyo
  • Error Codes
  • About Pricing
  • APIs
    • Send OTP
      GET
    • Send OTP
      POST
    • Verify OTP
      GET
    • Verify Token
      POST
  • Web SDKs
    • JavaScript
    • PHP
    • AngularJS Examples
    • TypeScript Examples
    • React JS
    • Vue JS Examples
  • Native/Mobile SDKs
    • Flutter
  1. Web SDKs

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-sdk"></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-sdk.js";
  script.setAttribute("data-appkey", "YOUR_APP_KEY");
  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-sdk.js";
script.setAttribute("data-appkey", "123456-app-key-xyz");
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-sdk"></div>;
};

export default AuthyoLogin;

Customization (Auto-loaded from Dashboard)

Your App Key controls these settings:

  • āœ… Logo, Header, Body Text
  • āœ… Button Shape, Color, Radius
  • āœ… Input Styling
  • āœ… Social Media Button Layout
  • āœ… Hide/Show Branding
  • āœ… Terms & Privacy Links

Supported Login Methods

  • āœ… Email OTP
  • āœ… SMS / WhatsApp / Voicecall
  • āœ… QR Code Login
  • āœ… Google / Microsoft / LinkedIn / GitHub

Response Structure

{
  "success": true,
  "message": "OTP verified successfully", 
  "data": {
    "email": "abc@xyz.com"
  }
}

Troubleshooting

ProblemSolution
SDK Not LoadingMake sure #authyo-sdk is rendered before script
No CallbackEnsure window.authyoResponse is defined
Blank WidgetCheck if data-appkey is valid
Incorrect StyleUpdate design settings in dashboard
Modified atĀ 2025-08-23 07:36:42
Previous
TypeScript Examples
Next
Vue JS Examples
Built with