Place the SDK container inside your component (e.g., AuthyoLogin.js
):
<div id="authyo-sdk"></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-sdk.js";
script.setAttribute("data-appkey", "YOUR_APP_KEY");
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-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;
Your App Key controls these settings:
{
"success": true,
"message": "OTP verified successfully",
"data": {
"email": "abc@xyz.com"
}
}
Problem | Solution |
---|---|
SDK Not Loading | Make sure #authyo-sdk is rendered before script |
No Callback | Ensure window.authyoResponse is defined |
Blank Widget | Check if data-appkey is valid |
Incorrect Style | Update design settings in dashboard |