This guide will walk you through integrating OneSDK with a Vue.js application, covering both Webpack and Vite setups.

Quick Start

1

Create a New Vue Project

Choose your preferred bundler:

# Install Vue CLI globally npm install -g @vue/cli # Create new
$project vue create my-onesdk-app
2

Install OneSDK

$npm install @frankieone/one-sdk
3

Configure Environment Variables

Create a .env file in your project root:

VUE_APP_CUSTOMER_ID=your_customer_id
VUE_APP_CUSTOMER_CHILD_ID=your_child_id
VUE_APP_API_KEY=your_api_key

Never commit sensitive credentials to version control. Add .env to your .gitignore file.

Implementation

Create or update your ./src/App.vue:

App.vue
1<script setup>
2import { onMounted, ref } from 'vue'
3import OneSdk from '@frankieone/one-sdk'
4
5// Configuration references
6const CUSTOMER_ID = import.meta.env.VITE_CUSTOMER_ID
7const CUSTOMER_CHILD_ID = import.meta.env.VITE_CUSTOMER_CHILD_ID
8const API_KEY = import.meta.env.VITE_API_KEY
9
10const session = ref(null)
11const tokenResult = ref(null)
12
13onMounted(async () => {
14// Initialize session
15const tokenResult = await initializeSession()
16
17// Configure OneSDK
18const oneSdk = await setupOneSdk(tokenResult)
19
20// Setup individual verification
21const individual = setupIndividual(oneSdk)
22
23// Initialize IDV flow
24setupIDVFlow(oneSdk)
25})
26
27// Session initialization
28async function initializeSession() {
29const response = await fetch("https://backend.latest.frankiefinancial.io/auth/v2/machine-session", {
30method: "POST",
31headers: {
32"authorization": "machine " + btoa(`${CUSTOMER_ID}:${CUSTOMER_CHILD_ID}:${API_KEY}`),
33"Content-Type": "application/json"
34},
35body: JSON.stringify({
36permissions: {
37"preset": "one-sdk",
38"reference": `demo-${new Date().toISOString()}`
39}
40})
41})
42return await response.json()
43}
44
45// OneSDK configuration
46async function setupOneSdk(tokenResult) {
47const sdk = await OneSdk({
48session: tokenResult.session,
49mode: "development",
50recipe: {
51form: {
52provider: {
53name: 'react',
54googleApiKey: 'YOUR_GOOGLE_API_KEY'
55},
56}
57}
58})
59
60sdk.on('\*', console.log)
61return sdk
62}
63
64// Individual verification setup
65function setupIndividual(sdk) {
66const individual = sdk.individual()
67individual.addConsent("general")
68individual.addConsent("docs")
69individual.addConsent("creditheader")
70return individual.submit()
71}
72
73// IDV flow setup
74function setupIDVFlow(sdk) {
75const idv = sdk.flow("idv")
76const components = {
77loading1: sdk.component("form", {
78name: "LOADING",
79title: { label: "Loading..." },
80descriptions: [{ label: "" }]
81}),
82loading2: sdk.component("form", {
83name: "LOADING",
84title: { label: "Processing results..." },
85descriptions: [{
86label: "Hold tight, this can take up to 30 seconds. Please don't refresh this page."
87}]
88}),
89review: sdk.component("form", {
90name: "REVIEW",
91type: "ocr"
92})
93}
94
95setupIDVEventHandlers(idv, components)
96idv.mount("#e2e-idv-container")
97}
98
99// Event handlers setup
100function setupIDVEventHandlers(idv, components) {
101let isInitialLoading = true
102
103idv.on("loading", (display) => handleLoading(display, components, isInitialLoading))
104idv.on("results", (data) => handleResults(data, components))
105idv.on("error", handleError)
106idv.on("detection_complete", handleDetectionComplete)
107
108components.review.on("form:review:ready", handleReviewReady)
109}
110
111</script>
112
113<template>
114 <div class="onesdk-container">
115 <div id="e2e-idv-container" class="idv-container"></div>
116 <div id="e2e-idv-loading1"></div>
117 <div id="e2e-idv-loading2"></div>
118 </div>
119</template>
120
121<style scoped>
122.onesdk-container {
123 width: 100%;
124 height: 85vh;
125}
126
127.idv-container {
128 width: 100%;
129 height: 100%;
130}
131</style>

Event Handling

1function handleLoading(display, components, isInitialLoading) {
2 if (display) {
3 if (isInitialLoading) {
4 components.loading1.mount("#e2e-idv-loading1")
5 }
6 } else {
7 if (isInitialLoading) {
8 components.loading1.unmount()
9 isInitialLoading = false
10 }
11 }
12}
1function handleResults({ checkStatus }, components) {
2 if (checkStatus) {
3 console.log("Verification successful")
4 components.loading2.unmount()
5 components.review.mount("#e2e-idv-container")
6 } else {
7 console.warn("No data returned")
8 }
9}
1function handleError({ message, payload }) {
2 console.error("Verification error:", message, payload)
3}

Running the Application

1

Start Development Server

$npm run serve
2

Access the Application

Open your browser and navigate to:

  • Webpack: http://localhost:8080
  • Vite: http://localhost:5173
Development Best Practices
  • Keep sensitive configuration in .env files
  • Implement proper error handling for API calls
  • Use Vue’s Composition API for better code organization
  • Consider implementing loading states for better UX

Troubleshooting

  • Session Token Issues: Ensure your credentials are correct in the .env file
  • Mounting Errors: Check that container IDs match exactly
  • Component Loading: Verify all required components are properly initialized
  • Vue Version: Ensure you’re using Vue 3.x
  • Node Version: Use Node.js 18.x or later
  • Build Issues: Clear npm cache and node_modules if encountering build problems
Built with