1-
1+ const tokenServerURL = import . meta . env . VITE_TOKEN_SERVER_URL
22let onBoarding ;
33let response ;
4- const container = document . getElementById ( "camera- container" ) ;
4+ const container = document . getElementById ( "container" ) ;
55
66function 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
1111function 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
3046async 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