Vue - iProov/web GitHub Wiki
Integrating with Vue 3 is straightforward. Install the @iproov/web-sdk package, serve its iProovMe.js from your application exactly as published, and render the <iproov-me> web component with your generated token.
âšī¸ Supported versions. We support any Vue version still receiving security patches. Vue 2 reached end of life on 31 December 2023, so that means Vue 3 and above. The iProov Web SDK is tested with Vue 3 using Vite.
App.vue
<script setup lang="ts">
import IProov from "./components/IProov.vue"
</script>
<template>
<header>
<div class="wrapper">
<IProov />
</div>
</header>
</template>components/IProov.vue
<template>
<div class="iproov">
<div v-if="loading" class="loading">Loading...</div>
<div v-if="error" class="error">{{ error }}</div>
<div v-if="token">
<iproov-me
:token="token"
base_url="***YOUR_BASE_URL***"
assets_url="***YOUR_ASSETS_URL***"
/>
</div>
</div>
</template>
<script>
const SDK_URL = new URL("/iproov/iProovMe.js", window.location.href).href
export default {
data() {
return {
token: "",
loading: true,
error: "",
}
},
async mounted() {
await import(/* webpackIgnore: true */ /* @vite-ignore */ SDK_URL)
this.fetchToken()
},
methods: {
generateUsername() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8
return v.toString(16)
})
},
async fetchToken() {
try {
// Replace with your backend token endpoint
const response = await fetch("***YOUR_BACKEND_TOKEN_ENDPOINT***", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
resource: "https://iproov.app",
user_id: `${this.generateUsername()}@example.com`,
client: "Web SDK Vue",
}),
})
if (!response.ok) throw new Error(response.statusText)
const data = await response.json()
if (!data.token) throw new Error("No token returned")
this.loading = false
this.token = data.token
} catch (err) {
this.loading = false
this.error = err.toString()
console.error(err)
}
},
},
}
</script>Vue 3 with Vite requires telling the compiler that <iproov-me> is a custom element so it doesn't try to resolve it as a Vue component:
vite.config.ts
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "iproov-me",
},
},
}),
],
})The Support Checker has its own subpath, and unlike iProovMe.js it can be imported through Vite as normal:
import { iProovSupport } from "@iproov/web-sdk/iProovSupport.js"
const supportChecker = new iProovSupport()
const { supported, granted, is_native_bridge } = await supportChecker.check()Pass custom slots as children of the <iproov-me> component:
<iproov-me :token="token" base_url="***YOUR_BASE_URL***" assets_url="***YOUR_ASSETS_URL***">
<div slot="ready">Ready to scan</div>
<div slot="button">Start scanning</div>
<div slot="passed">Verification passed!</div>
<div slot="failed">Verification failed</div>
</iproov-me>iProovMe.js must reach the browser exactly as published: if a bundler such as Vite bundles, pre-bundles or minifies it, every transaction fails. That is why the component loads it by URL in mounted() instead of importing @iproov/web-sdk.
Copy iProovMe.js, with iproov-assets/ if you self-host the assets, into a folder your build serves as-is, before each dev server start and build. With Vite, that is public/:
scripts/copy-iproov.mjs
import { cpSync, rmSync } from "node:fs"
const sdk = "node_modules/@iproov/web-sdk"
const out = "public/iproov"
rmSync(out, { recursive: true, force: true })
cpSync(`${sdk}/iProovMe.js`, `${out}/iProovMe.js`)
cpSync(`${sdk}/iproov-assets`, `${out}/iproov-assets`, { recursive: true })package.json
{
"scripts": {
"dev": "node scripts/copy-iproov.mjs && vite",
"build": "node scripts/copy-iproov.mjs && vite build"
}
}- Add
public/iproov/to.gitignore. - Keep
SDK_URLabsolute, as in the component: Vite's dev server refuses a root-relative import of a file inpublic/. - Set
assets_urltohttps://your.app.example/iproov/to load the rest of the SDK from the copy, or leave it unset to load it from cdn.iproov.app and drop the script'siproov-assetsline.
See Loading the SDK for the full recipe.