Place this inside your component template (e.g., app.component.html
):
<div id="authyo-sdk"></div>
Load the Authyo script dynamically in your ngOnInit
method:
// app.component.ts
ngOnInit(): void {
const script = document.createElement('script');
script.src = 'https://app.authyo.io/js/v1/auth-sdk.js';
script.setAttribute('data-appkey', 'YOUR_APP_KEY');
document.body.appendChild(script);
}
Declare window.authyoResponse
globally and type the expected structure:
// typings.d.ts or inside component interface AuthyoResponse { success: boolean; message: string; status?: string; data?: any; }
declare global {
interface Window {
authyoResponse: (response: AuthyoResponse) => void;
}
}// Inside ngOnInit
window.authyoResponse = (response: AuthyoResponse): void => {
if (response.success) {
console.log("ā Verified:", response.data);
} else {
console.error("ā Failed:", response.message);
}
};
// app.component.html <div id="authyo-sdk"></div>
// app.component.ts
import { Component, OnInit } from '@angular/core';interface AuthyoResponse {
success: boolean;
message: string;
data?: any;
}@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
ngOnInit(): void {
const script = document.createElement('script');
script.src = 'https://app.authyo.io/js/v1/auth-sdk.js';
script.setAttribute('data-appkey', '123456-app-key-xyz');
document.body.appendChild(script);
window.authyoResponse = (response: AuthyoResponse): void => {
if (response.success) {
console.log('ā User verified:', response.data);
} else {
console.log('ā Login failed:', response.message);
}
};
}
}
Your App Key controls these:
{
"success": true,
"message": "OTP verified successfully",
"status": "verified",
"data": {
"email": "abc@xyz.com"
}
}
Problem | Solution |
---|---|
Widget not loading | Ensure #authyo-sdk is in the DOM before loading script |
No callback triggered | Declare window.authyoResponse globally |
Blank screen | Make sure data-appkey is correct and active |
Styling off | Customize in your Authyo dashboard |