JavaScript SDK
API Reference
Reference for the exported SDK functions, config options, and core TypeScript types.
API Reference
The package exports a small browser-focused API surface.
Main functions
| Function | Purpose |
|---|---|
init(config) | Store and validate your SDK configuration |
startVerificationWithRedirect() | Start verification with a full-page redirect |
startVerificationWithPopup(popup?) | Start verification in a popup window |
handleRedirectResult(options) | Process the returned JWT on the callback page |
isVerified() | Check whether a valid verification token is stored |
getVerifiedAge() | Read the verified age from the stored token |
resetVerification() | Clear the stored verification state |
init(config)
Call init() before any verification start function.
init({
publicKey: 'pk_test_your_key',
ageToVerify: 18,
redirectUri: 'https://your-app.com/verification-result',
onVerified: (payload) => {},
onDenied: (outcome) => {},
onCancelled: (outcome) => {},
onError: (outcome) => {},
onFailure: (error) => {},
debug: false,
})Config type
| Field | Type | Required |
|---|---|---|
publicKey | string | Yes |
ageToVerify | number | Yes |
redirectUri | string | Yes |
onVerified | (payload) => void | Yes |
onFailure | (error?) => void | No |
onDenied | (outcome) => void | No |
onCancelled | (outcome) => void | No |
onError | (outcome) => void | No |
debug | boolean | No |
startVerificationWithRedirect()
Starts a full-page redirect flow.
- Use this when a redirect is acceptable
- Call
handleRedirectResult()on the callback page afterward - If the user is already verified, the SDK can call
onVerifiedimmediately instead of starting a new flow
startVerificationWithPopup(popup?)
Starts a popup-based verification flow.
- If you pass a pre-opened popup, the SDK uses it
- If the popup is blocked, you can receive
POPUP_BLOCKED - The SDK guards against overlapping popup flows on the same page
handleRedirectResult(options)
This function belongs on the callback page.
Options
| Field | Purpose |
|---|---|
onVerified | Required success callback |
onFailure | Legacy catch-all failure callback |
onDenied | Called for UNDER_AGE |
onError | Called for technical failures |
targetOrigin | Recommended for popup callback pages |
Helper functions
isVerified()
Returns true if a valid, non-expired verification token is stored.
getVerifiedAge()
Returns the verified age as a number, or null if the user is not verified.
resetVerification()
Clears the verification cookie so your app can require a fresh verification.
Core types
VerificationOutcome
type VerificationOutcome = {
code: VerificationErrorCode
message: string
raw?: unknown
}VerificationErrorCode
type VerificationErrorCode =
| 'UNDER_AGE'
| 'POPUP_CLOSED'
| 'USER_CANCELLED'
| 'POPUP_BLOCKED'
| 'POPUP_TIMEOUT'
| 'UNTRUSTED_ORIGIN'
| 'NETWORK_ERROR'
| 'TOKEN_INVALID'
| 'UNKNOWN_ERROR'