Skip to content

Commit 6b87c90

Browse files
committed
simplified error messages and container
1 parent 9d7a74e commit 6b87c90

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

face-login/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
</head>
1111
<body>
1212
<main id="app">
13-
<div id="camera-container"></div>
14-
<div id="finish-container"></div>
13+
<div id="container"></div>
1514
</main>
1615
</body>
1716
</html>

face-login/main.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1-
1+
const tokenServerURL= import.meta.env.VITE_TOKEN_SERVER_URL
22
let onBoarding;
33
let response;
4-
const container = document.getElementById("camera-container");
4+
const container = document.getElementById("container");
55

66
function showError(e=null) {
7-
container.innerHTML = "<h1>There was an error</h1>";
8-
console.log(e)
7+
container.innerHTML = "<h1>Something Went Wrong, see console for details</h1>";
8+
console.dir(e)
99
}
1010

1111
function identifyUser(){
1212
onBoarding.renderLogin(container,{
13-
onSuccess: response => {
14-
console.log(response);
15-
finish(response)
16-
// User has an Incode Identity. Add success your logic here
13+
onSuccess: async (response) => {
14+
const {token, transactionId, interviewToken, faceMatch, customerId, email} = response;
15+
if (faceMatch){
16+
// User has an Incode Identity.
17+
// Validate using your backend that the faceMatch was actually valid and not man in the middle attack
18+
const response = await fetch(`${tokenServerURL}/auth`,
19+
{
20+
method: "POST",
21+
mode: "cors",
22+
body: JSON.stringify({token,transactionId: transactionId, interviewToken})
23+
}
24+
);
25+
const authAttempt = await response.json();
26+
if(authAttempt.verified===true){
27+
finish(customerId, email);
28+
} else {
29+
showError(new Error("FaceMatch is invalid."));
30+
}
31+
} else {
32+
showError(new Error("Face did not match any user."));
33+
}
1734
},
1835
onError: error => {
1936
showError(error)
@@ -22,9 +39,8 @@ function identifyUser(){
2239
});
2340
}
2441

25-
function finish(response) {
26-
const container = document.getElementById("finish-container");
27-
container.innerHTML = "<pre>"+JSON.stringify(response, undefined, 2);+"</pre>";
42+
function finish(customerId, email) {
43+
container.innerHTML = `<h1>Sucessfull Login:</h1>\n<p>CustomerId: ${customerId}</p>\n<p>Email: ${email}</p>`;
2844
}
2945

3046
async function app() {
@@ -44,9 +60,7 @@ async function app() {
4460
container.innerHTML = "";
4561
identifyUser();
4662
} catch (e) {
47-
console.dir(e);
48-
container.innerHTML = "<h1>Something Went Wrong</h1>";
49-
throw e;
63+
showError(e);
5064
}
5165
}
5266

0 commit comments

Comments
 (0)