-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobile.js
66 lines (55 loc) · 2.22 KB
/
mobile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import truliooDocV from "https://cdn.jsdelivr.net/npm/@trulioo/docv/+esm";
const { Trulioo, event } = truliooDocV;
async function initializeSDK() {
// Extract the shortCode and locale from the URL
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const shortCodeParam = urlParams.get("code");
const localeParam = urlParams.get("locale");
const host = "https://fdthvh-8080.csb.app/"; // Desktop URL for redirection after completion
// Fetch the shortCode from the backend
const response = await fetch(
"https://fdthvh-8080.csb.app/get-stored-shortCode"
);
const data = await response.json();
const shortCode = data.shortCode;
let selectedShortCode = shortCodeParam; // Use the obtained short code from the url param
if (shortCodeParam === null) {
selectedShortCode = shortCode; // Use the obtained short code from the Trulioo Customer API
}
// Set up the workflow options
const workflowOption = Trulioo.workflow()
.setShortCode(selectedShortCode)
.setRedirectUrl(host);
if (localeParam !== null) {
workflowOption.setLanguage(localeParam);
}
// Set up callbacks to get results and debugging errors
const callbacks = new event.adapters.ListenerCallback({
onComplete: (success) => {
console.info(`Verification Successful: ${success.transactionId}`);
},
onError: (error) => {
console.error(
`Verification Failed with Error Code: ${error.code}, TransactionID: ${error.transactionId}, Reason: ${error.message}`
);
},
onException: (exception) => {
console.error("Verification Failed with Exception:", exception);
},
});
const callbackOption = Trulioo.event().setCallbacks(callbacks);
// Initialize the Trulioo SDK
Trulioo.initialize(workflowOption)
.then((complete) => {
console.info("Mobile Initialize complete:", complete);
Trulioo.launch("trulioo-sdk", callbackOption).then((success) => {
console.info("Mobile Launch success:", success);
});
})
.catch((error) =>
console.error("Error initializing mobile workflow:", error)
);
}
// Call the function to initialize the SDK
initializeSDK();