Gå til hovedindhold
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

FunctionPurpose
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

FieldTypeRequired
publicKeystringYes
ageToVerifynumberYes
redirectUristringYes
onVerified(payload) => voidYes
onFailure(error?) => voidNo
onDenied(outcome) => voidNo
onCancelled(outcome) => voidNo
onError(outcome) => voidNo
debugbooleanNo

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 onVerified immediately 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

FieldPurpose
onVerifiedRequired success callback
onFailureLegacy catch-all failure callback
onDeniedCalled for UNDER_AGE
onErrorCalled for technical failures
targetOriginRecommended 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'
  1. Error Handling
  2. Installation
  3. Migration

On this page