|
| 1 | + |
| 2 | +let onBoarding; |
| 3 | +let response; |
| 4 | +const container = document.getElementById("camera-container"); |
| 5 | + |
| 6 | +function showError(e=null) { |
| 7 | + container.innerHTML = "<h1>There was an error</h1>"; |
| 8 | + console.log(e) |
| 9 | +} |
| 10 | + |
| 11 | +function identifyUser(){ |
| 12 | + onBoarding.renderLogin(container,{ |
| 13 | + onSuccess: response => { |
| 14 | + console.log(response); |
| 15 | + finish(response) |
| 16 | + // User has an Incode Identity. Add success your logic here |
| 17 | + }, |
| 18 | + onError: error => { |
| 19 | + showError(error) |
| 20 | + // User not found. Add rejection your logic here |
| 21 | + }, |
| 22 | + }); |
| 23 | +} |
| 24 | + |
| 25 | +function finish(response) { |
| 26 | + const container = document.getElementById("finish-container"); |
| 27 | + container.innerHTML = "<pre>"+JSON.stringify(response, undefined, 2);+"</pre>"; |
| 28 | +} |
| 29 | + |
| 30 | +async function app() { |
| 31 | + try { |
| 32 | + // Create the instance of incode linked to a client |
| 33 | + const apiURL = import.meta.env.VITE_API_URL; |
| 34 | + const clientId = import.meta.env.VITE_CLIENT_ID; |
| 35 | + const apiKey =import.meta.env.VITE_API_KEY; |
| 36 | + |
| 37 | + onBoarding = window.OnBoarding.create({clientId,apiURL,apiKey}); |
| 38 | + |
| 39 | + // Incode web_sdk need to preload some core component before being usable |
| 40 | + container.innerHTML = "<h1>Warming up...</h1>"; |
| 41 | + await onBoarding.warmup(); |
| 42 | + |
| 43 | + // Empty the container and starting the flow |
| 44 | + container.innerHTML = ""; |
| 45 | + identifyUser(); |
| 46 | + } catch (e) { |
| 47 | + console.dir(e); |
| 48 | + container.innerHTML = "<h1>Something Went Wrong</h1>"; |
| 49 | + throw e; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +document.addEventListener("DOMContentLoaded", app); |
0 commit comments