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

  1. Your app calls init()
  2. Your app calls startVerificationWithRedirect()
  3. The SDK sends the user to the verification provider
  4. The user returns to your redirectUri with a jwt query parameter
  5. Your callback page calls handleRedirectResult()
  6. 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 a jwt parameter in the URL
  • The SDK removes the jwt parameter 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 into onVerified

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

Next step

Learn popup flow

On this page