JavaScript SDK
Redirect Flow
Use the SDK with a full-page redirect and a callback page that processes the verification result.
Redirect Flow
Redirect flow is the simplest way to integrate the SDK.
The user leaves your current page, completes MitID verification, and returns to your redirectUri. That callback page must call handleRedirectResult().
Flow overview
- Your app calls
init() - Your app calls
startVerificationWithRedirect() - The SDK sends the user to the verification provider
- The user returns to your
redirectUriwith ajwtquery parameter - Your callback page calls
handleRedirectResult() - The SDK validates the token, stores it, and triggers your callbacks
Main page example
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('Already verified or just completed verification', payload)
},
onDenied: (outcome) => {
console.warn(outcome.code)
},
onCancelled: (outcome) => {
console.warn(outcome.code)
},
onError: (outcome) => {
console.error(outcome.code, outcome.message)
},
})
if (!isVerified()) {
startVerificationWithRedirect()
}Callback page example
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)
},
})Important behavior
handleRedirectResult()expects ajwtparameter in the URL- The SDK removes the
jwtparameter from the URL after processing - The verification token is stored so later calls to
isVerified()can succeed - If the user is already verified,
startVerificationWithRedirect()can short-circuit intoonVerified
When to choose redirect flow
Choose redirect flow when:
- You want the simplest implementation
- You do not need the original page to stay visible during verification
- You are integrating into a classic website or storefront
Choose popup flow instead if your UI should remain on the current page.
Common issues
- No callback page exists at the
redirectUri - The callback page forgets to call
handleRedirectResult() - The whitelisted domain does not match the environment you are testing
- You expect a popup-style cancel callback in a full-page redirect flow