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

You 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

FieldRequiredDescription
publicKeyYesYour pk_test_... or pk_live_... public key
ageToVerifyYesMinimum age to verify, for example 18
redirectUriYesCallback page where the user returns after verification
onVerifiedYesCalled when verification succeeds
onDeniedNoCalled when the result is UNDER_AGE
onCancelledNoCalled when the popup is closed or cancelled before completion
onErrorNoCalled on technical failures such as invalid token or network issues
onFailureNoLegacy catch-all callback kept for backwards compatibility
debugNoEnables verbose SDK logging

Test mode vs production

EnvironmentKey prefixDomainUse case
Testpk_test_Your test or staging domainDevelopment and QA
Productionpk_live_Your live domainReal 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 redirectUri at a page that never calls handleRedirectResult()

Next steps

  1. Understand the redirect flow
  2. Use popup mode instead
  3. See the Vite + React example

On this page