- npm
- Script Tag
Installation
Install the OTPless Headless SDK with your favorite package manager:🚀 Quick Start (React Example)
🧑💻 API Reference
useOTPless()
Returns an object with:| Property | Type | Description |
|---|---|---|
| ready | boolean | Whether the OTPless SDK script is loaded and ready. |
| loading | boolean | true if any operation (init/initiate/verify) is in progress. |
| init | (appId: string) => Promise<void> | Initialize the SDK with your App ID. Call once before use. |
| initiate | (request: InitiateRequest) => Promise<OTPlessResponse> | Send OTP (via CHANNELS.PHONE, etc). |
| verify | (request: VerifyRequest) => Promise<OTPlessResponse> | Verify the OTP received by the user. |
| on | (see below) | Subscribe to events; signature below. |
| off | (event, callback) => void | Remove a previously registered listener. |
on(event, handler?)
- Subscribe to a single event:
- Or to multiple events at once:
- Returns an unsubscribe function.
off(event, handler)
- Unsubscribe a specific event handler.
TypeScript Types & Constants
OTPless Response Type
All SDK calls (initiate, verify) return:⚡️ Framework-Agnostic Usage
You can use the SDK without React (in any framework):🛠 Utility Functions
🟢 Next.js Usage
For Next.js App Router, add 'use client'; at the top of your component file!
Find npm package here: https://www.npmjs.com/package/otpless-headless-js Find github repository here: https://github.com/otpless-tech/web-headless-demo Find sandbox here: https://codesandbox.io/s/github/otpless-tech/web-headless-demo
🏁 Checkpoint
To ensure a smooth integration process:- Deploy your app/website with the included OTPLESS SDK.
- Conduct tests to verify the sign-in flow functions correctly.
- Ensure that after a successful sign-in, the user is redirected back to your app/website and their information is correctly logged in the console.
User Information Response Structure
The structure of the user information returned upon successful sign-in is as follows:Next Steps
Validate ID Token
Learn how to securely `validate ID token` returned by OTPLESS javascript SDK to ensure the authenticity of sign-in events from your backend server.
Validate Token (Opaque)
Learn how to securely `validate token` returned by OTPLESS javascript SDK to ensure the authenticity of sign-in events from your backend server.