@@ -31,47 +31,30 @@ const start = async function (identityId) {
3131
3232 // The session response has many values, but you should only pass the token to the frontend.
3333 const responseData = await response . json ( ) ;
34- const { token, interviewId } = responseData ;
34+ const { token } = responseData ;
3535
36- // Store session in local DB, session will be created as used: false.
37- await addSession ( interviewId , token , identityId ) ;
38-
39- return { token, interviewId } ;
36+ return { token } ;
4037} ;
4138
4239// Public: Verify the authentication by checking the score and session data
43- const getResults = async function ( interviewId , token , candidate ) {
44-
45- // Prevents usage of candidate that doesn't match the identityId stored in session.
46- if ( session . identityId !== candidate ) {
47- // Mark the session as rejected.
48- await updateSession ( interviewId , "rejected" ) ;
49- return {
50- // Detailed debug message, in production you might want to avoid exposing internal details.
51- message : "identityId and candidate mismatch for interviewId " + interviewId ,
52- isValid : false ,
53- } ;
54- }
40+ const getResults = async function ( token , candidate ) {
5541
5642 // Finishing the session triggers score calculation and business rules.
5743 await finishStatus ( token ) ; // Mark session as finished in Incode backend
44+
5845 // Closing the session stop it from being changed, all /add/ endpoints will be rejected after this, and the score will be frozen.
5946 await setStatusClosed ( token ) ; // Mark session as closed in Incode backend
6047
61-
6248 let identityId , scoreStatus ;
6349 try {
64- // At this point we already verified that the token matches, but
65- // to be clear about our intentions, we use the token stored in the
66- // database to get the identityId and compare it with the candidate.
6750 const scoreResponse = await getScore ( token ) ;
6851 identityId = scoreResponse . authentication . identityId ;
6952 scoreStatus = scoreResponse . overall . status ;
7053 } catch ( e ) {
7154 // If there is an error communicating with API, we consider validation failed.
7255 return {
7356 // Detailed debug message, in production you might want to avoid exposing internal details.
74- message : "Error validating authentication for interviewId " + interviewId + " : " + e . message ,
57+ message : "Error validating authentication: " + e . message ,
7558 isValid : false ,
7659 } ;
7760 }
@@ -81,7 +64,7 @@ const getResults = async function (interviewId, token, candidate) {
8164 if ( identityId !== candidate ) {
8265 return {
8366 // Detailed debug message, in production you might want to avoid exposing internal details.
84- message : "Session data doesn't match for interviewId " + interviewId ,
67+ message : "candidate " + candidate + " does not match identityId " + identityId + " from score" ,
8568 isValid : false ,
8669 } ;
8770 }
@@ -90,15 +73,15 @@ const getResults = async function (interviewId, token, candidate) {
9073 if ( scoreStatus !== "OK" ) {
9174 return {
9275 // Detailed debug message, in production you might want to avoid exposing internal details.
93- message : "Face Validation failed for interviewId " + interviewId ,
76+ message : "Face Validation failed for candidate " + candidate ,
9477 isValid : false ,
9578 } ;
9679 }
9780
9881 // Only valid if all checks passed, we return the identityId that was validated.
9982 return {
10083 // Detailed debug message, in production you might want to avoid exposing internal details.
101- message : "Face Validation succeeded for interviewId " + interviewId ,
84+ message : "Face Validation succeeded for candidate " + candidate ,
10285 isValid : true ,
10386 identityId : identityId ,
10487 } ;
@@ -140,9 +123,17 @@ const setStatusClosed = async function (token) {
140123 } catch ( e ) {
141124 throw new Error ( "HTTP Post Error: " + e . message ) ;
142125 }
143- const results = await response . json ( ) ;
144- console . log ( { results} ) ;
145- return results ;
126+ const { sessionStatus} = await response . json ( ) ;
127+ /* Example response
128+ {
129+ "_id": "69c5c01ac40764536244ac3b",
130+ "_createdAt": 1774567450715,
131+ "_updatedAt": 1774567469629,
132+ "closedAt": 1774567469629,
133+ "sessionStatus": "Closed"
134+ }
135+ */
136+ return { sessionStatus} ;
146137} ;
147138
148139// Private: Call Incode's `omni/get/score` API to retrieve the score for the session
0 commit comments