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

TypeScript Examples

JavaScript SDK

TypeScript Integration

Step 1: Add the Container

Place this inside your component template (e.g., app.component.html):

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

Step 2: Include the SDK Dynamically

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-2fasdk.js';
  script.setAttribute('data-appkey', 'YOUR_APP_KEY');
  script.setAttribute('data-emailid', 'abc@xyz.com');
  document.body.appendChild(script);
}

Step 3: Handle the Response with Typing

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);
}
};

Example: Full Integration (TypeScript)

// app.component.html
<div id="authyo-2fasdk"></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-2fasdk.js';
script.setAttribute('data-appkey', '123456-app-key-xyz');
script.setAttribute('data-emailid', 'abc@xyz.com');
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);
}
};
}
}

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:37
Previous
React JS
Next
Vue JS Examples
Built with