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

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-sdk"></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-sdk.js';
  script.setAttribute('data-appkey', 'YOUR_APP_KEY');
  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-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);
}
};
}
}

Customization (Auto-loaded from Dashboard)

Your App Key controls these:

  • āœ… Logo, header, body text
  • āœ… Button shape, color, text
  • āœ… Input styles and colors
  • āœ… Show/hide social logins and branding
  • āœ… Positioning of OAuth buttons
  • āœ… 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",
  "status": "verified",
  "data": {
    "email": "abc@xyz.com"
  }
}

Troubleshooting

ProblemSolution
Widget not loadingEnsure #authyo-sdk is in the DOM before loading script
No callback triggeredDeclare window.authyoResponse globally
Blank screenMake sure data-appkey is correct and active
Styling offCustomize in your Authyo dashboard
Modified atĀ 2025-08-23 07:36:18
Previous
AngularJS Examples
Next
React JS
Built with