JavaScript SDK
Installation
Install and configure the Aldersverificering SDK in your project.
Installation
This page is the main quickstart for @unqtech/age-verification-mitid.
It covers the current SDK API and replaces the older quickstart that used outdated package names and startup functions.
Need the same flow without the package? See Custom Integrations for the raw browser-facing API contract and JWT validation steps.
Prerequisites
Before you integrate the SDK, make sure you have:
- A UNQVerify account
- A public API key from API Keys
- A whitelisted domain in Domains
- A callback URL that will act as your
redirectUri
Use a pk_test_... key while developing and a pk_live_... key when going live.
The
redirectUri must match a real page in your app and should be registered as an allowed redirect URI in your dashboard.Install the package
pnpm add @unqtech/age-verification-mitidYou can also use npm install @unqtech/age-verification-mitid if your project uses npm.
Minimal redirect flow
This is the fastest way to get the SDK working in a browser app.
1. Initialize the SDK
import {
init,
isVerified,
startVerificationWithRedirect,
} from '@unqtech/age-verification-mitid'
init({
publicKey: 'pk_test_your_key',
ageToVerify: 18,
redirectUri: 'https://your-app.com/verification-result',
onVerified: (payload) => {
console.log('Verified', payload)
},
onDenied: (outcome) => {
console.warn('Denied', outcome.code)
},
onCancelled: (outcome) => {
console.warn('Cancelled', outcome.code)
},
onError: (outcome) => {
console.error('Error', outcome.code, outcome.message)
},
})
if (!isVerified()) {
startVerificationWithRedirect()
}2. Process the result on your callback page
Create the page you used as redirectUri and call handleRedirectResult() there.
import { handleRedirectResult } from '@unqtech/age-verification-mitid'
await handleRedirectResult({
onVerified: (payload) => {
console.log('JWT verified', payload)
window.location.href = '/'
},
onDenied: (outcome) => {
console.warn('Denied', outcome.code)
},
onError: (outcome) => {
console.error('Technical error', outcome.code, outcome.message)
},
})Configuration fields
| Field | Required | Description |
|---|---|---|
publicKey | Yes | Your pk_test_... or pk_live_... public key |
ageToVerify | Yes | Minimum age to verify, for example 18 |
redirectUri | Yes | Callback page where the user returns after verification |
onVerified | Yes | Called when verification succeeds |
onDenied | No | Called when the result is UNDER_AGE |
onCancelled | No | Called when the popup is closed or cancelled before completion |
onError | No | Called on technical failures such as invalid token or network issues |
onFailure | No | Legacy catch-all callback kept for backwards compatibility |
debug | No | Enables verbose SDK logging |
Test mode vs production
| Environment | Key prefix | Domain | Use case |
|---|---|---|---|
| Test | pk_test_ | Your test or staging domain | Development and QA |
| Production | pk_live_ | Your live domain | Real user traffic |
Use test keys until your full callback flow works, then switch to production.
Common mistakes
- Using a public key that does not match the intended environment
- Forgetting to whitelist the callback domain
- Starting verification before calling
init() - Pointing
redirectUriat a page that never callshandleRedirectResult()