🚀 Quickstart: Age Verification SDK
This guide shows you how to integrate the
@unqtech/age-verification-mitid
SDK into your frontend application. You’ll learn how to initialize the SDK, start the verification process, and handle the result after the redirect or popup callback.1. 📦 Install the SDK
Install the @unqtech/age-verification package
Bash
pnpm add @unqtech/age-verification
2. 🧩 Initialize the SDK
Before starting the verification flow, you must call init() to configure the SDK with your:
The required options depend on the flow mode you want to use:
🔁 Redirect Mode
Redirects the user to MitID in the current browser tab.
TypeScript
import { init, start } from '@unqtech/age-verification-mitid'
init({
publicKey: 'pk_test_abc123',
ageToVerify: 18,
redirectUri: 'https://yourapp.com/verification-result',
mode: 'redirect',
onVerified: (payload) => {
console.log('✅ Verified via redirect:', payload)
},
onFailure: (error) => {
console.error('❌ Verification failed', error)
}
})
start()
This will send the user to MitID and return them to your /verification-result page, where you should call handleRedirectResult().
🪟 Popup Mode
Opens a new popup window for verification. This allows your app to stay visible during the flow.
TypeScript
import { init, startWithPopup } from '@unqtech/age-verification-mitid'
init({
publicKey: 'pk_test_abc123',
ageToVerify: 18,
redirectUri: 'https://yourapp.com/verify-popup', // this must match the popup handler page
mode: 'popup',
onVerified: (payload) => {
console.log('✅ Verified via popup:', payload)
},
onFailure: (error) => {
console.error('❌ Verification failed in popup', error)
}
})
startWithPopup()
On the /verify-popup page, use this handler:
TypeScript
import { handleRedirectResult } from '@unqtech/age-verification-mitid'
handleRedirectResult({
onVerified: (payload) => {
window.opener?.postMessage({ type: 'UNQVERIFY_RESULT', payload }, '*')
window.close()
},
onFailure: (err) => {
console.warn('❌ Verification failed in popup:', err)
window.close()
}
})
For both redirect and popup it is important that the redirect uri matches a page handler in your application.
3. 🚦 Check and Start Verification
You can check if the user is already verified using a simple function. If not, start the flow:
TypeScript
if (!isVerified()) {
start()
}
4. 🔁 Handle the Redirect Result
If you’re using the redirect flow, you’ll need to handle the callback URL where the user is redirected after completing the verification. This step is essential for processing the response and storing the verification result in a cookie.
We recommend setting up a dedicated page to handle the redirect result. On that page (your redirectUri), use the following code to finalize the verification process:
TypeScript
import { handleRedirectResult } from '@unqtech/age-verification-mitid'
handleRedirectResult({
onVerified: (payload) => {
console.log('✅ Token verified:', payload)
window.close() // Optional: auto-close popup or tab
},
onFailure: (err) => {
console.error('❌ Invalid token', err)
}
})
5. 🧹 Optional: Reset Verification
To clear the session manually (e.g. during logout), call:
TypeScript
import { resetVerification } from '@unqtech/age-verification-mitid'
resetVerification()
🔐 How It Works
Markdown
https://test.api.aldersverificering.dk/well-known/openid-configuration/jwks
https://api.aldersverificering.dk/well-known/openid-configuration/jwks