|
1 | 1 | const tokenServerURL= import.meta.env.VITE_TOKEN_SERVER_URL |
2 | 2 | let onBoarding; |
3 | | -const container = document.getElementById("container"); |
| 3 | + |
| 4 | +const mainContainer = document.getElementById("app"); |
| 5 | +const loginContainer = document.getElementById("login"); |
| 6 | +const loginButton = document.getElementById("login-button"); |
| 7 | + |
4 | 8 |
|
5 | 9 | function showError(e=null) { |
6 | | - container.innerHTML = "<h1>Something Went Wrong, see console for details</h1>"; |
7 | | - console.dir(e) |
| 10 | + mainContainer.innerHTML = "Something Went Wrong, see console for details..."; |
| 11 | + console.log(e) |
8 | 12 | } |
9 | 13 |
|
10 | | -function identifyUser(){ |
11 | | - onBoarding.renderLogin(container,{ |
| 14 | +function identifyUser(identityId){ |
| 15 | + onBoarding.renderLogin(mainContainer,{ |
12 | 16 | onSuccess: async (response) => { |
13 | 17 | const {token, transactionId, interviewToken, faceMatch, customerId, email} = response; |
14 | 18 | if (faceMatch){ |
15 | 19 | // User has an Incode Identity. |
16 | 20 | // Verify using your backend that the faceMatch was actually valid and |
17 | 21 | // not man in the middle attack |
18 | 22 | const response = await fetch(`${tokenServerURL}/auth`, |
19 | | - { |
| 23 | + { |
20 | 24 | method: "POST", |
21 | 25 | mode: "cors", |
22 | 26 | body: JSON.stringify({token,transactionId: transactionId, interviewToken}) |
23 | | - } |
24 | | - ); |
25 | | - const verification = await response.json(); |
26 | | - if(verification.verified===true){ |
27 | | - finish(customerId, email); |
28 | | - } else { |
29 | | - showError(new Error("FaceMatch is invalid.")); |
30 | 27 | } |
| 28 | + ); |
| 29 | + const verification = await response.json(); |
| 30 | + if(verification.verified===true){ |
| 31 | + finish(customerId, email); |
31 | 32 | } else { |
32 | | - showError(new Error("Face did not match any user.")); |
| 33 | + showError(new Error("FaceMatch is invalid.")); |
33 | 34 | } |
34 | | - }, |
35 | | - onError: error => { |
36 | | - showError(error) |
37 | | - // User not found. Add rejection your logic here |
38 | | - }, |
39 | | - // isOneToOne: true, |
40 | | - // oneToOneProps: { |
41 | | - // identityId: "uuid/customerId of the user you want to match", |
42 | | - // } |
43 | | - }); |
| 35 | + } else { |
| 36 | + showError(new Error("Face did not match any user.")); |
| 37 | + } |
| 38 | + }, |
| 39 | + onError: error => { |
| 40 | + showError(error) |
| 41 | + // User not found. Add rejection your logic here |
| 42 | + }, |
| 43 | + isOneToOne: true, |
| 44 | + oneToOneProps: { |
| 45 | + identityId: identityId, |
| 46 | + } |
| 47 | +}); |
44 | 48 | } |
45 | 49 |
|
46 | 50 | function finish(customerId, email) { |
47 | | - container.innerHTML = `<h1>Sucessfull Login:</h1>\n<p>CustomerId: ${customerId}</p>\n<p>Email: ${email}</p>`; |
| 51 | + mainContainer.innerHTML = `Sucessfull Login:<br/>\n<div>CustomerId: ${customerId}</div>\n<div>Email: ${email}</div>`; |
48 | 52 | } |
49 | 53 |
|
50 | 54 | async function app() { |
51 | | - try { |
52 | | - // Create the instance of incode linked to a client |
53 | | - const apiURL = import.meta.env.VITE_API_URL; |
54 | | - const clientId = import.meta.env.VITE_CLIENT_ID; |
55 | | - const apiKey = import.meta.env.VITE_API_KEY; |
56 | | - |
57 | | - onBoarding = window.OnBoarding.create({clientId, apiURL, apiKey}); |
58 | | - |
59 | | - // Incode web_sdk need to preload some core component before being usable |
60 | | - container.innerHTML = "<h1>Warming up...</h1>"; |
61 | | - await onBoarding.warmup(); |
62 | | - |
63 | | - // Empty the container and starting the flow |
64 | | - container.innerHTML = ""; |
65 | | - identifyUser(); |
66 | | - } catch (e) { |
67 | | - showError(e); |
68 | | - } |
| 55 | + // Create the instance of incode linked to a client |
| 56 | + const apiURL = import.meta.env.VITE_API_URL; |
| 57 | + // Enable for 1:N |
| 58 | + //const clientId = import.meta.env.VITE_CLIENT_ID; |
| 59 | + //const apiKey = import.meta.env.VITE_API_KEY; |
| 60 | + |
| 61 | + onBoarding = window.OnBoarding.create({ |
| 62 | + apiURL |
| 63 | + // clientId, // Enable for 1:N |
| 64 | + // apiKey // Enable for 1:N |
| 65 | + }); |
| 66 | + |
| 67 | + // Incode web_sdk need to preload some core component before being usable |
| 68 | + mainContainer.innerHTML = "Warming up..."; |
| 69 | + await onBoarding.warmup(); |
| 70 | + |
| 71 | + // Empty the message and starting the flow |
| 72 | + mainContainer.innerHTML = ""; |
| 73 | + loginContainer.style.display="flex"; |
| 74 | + loginButton.addEventListener('click', () =>{ |
| 75 | + const identityIdInput = document.getElementById("identity-id"); |
| 76 | + loginContainer.style.display="none"; |
| 77 | + identifyUser(identityIdInput.value) |
| 78 | + }) |
69 | 79 | } |
70 | | - |
| 80 | ++ |
71 | 81 | document.addEventListener("DOMContentLoaded", app); |
0 commit comments