11import { detectDuplicateIdentityFraud } from "@/lib/api/fraud/detect-duplicate-identity-fraud" ;
2- import { computeVeriffIdentityHash } from "@/lib/veriff/compute-veriff-identity-hash" ;
32import {
43 VeriffDecisionEvent ,
54 VeriffRiskLabel ,
@@ -62,7 +61,6 @@ export const handleDecisionEvent = async ({
6261
6362 // since we're skipping verified partners, by default identityVerifiedAt is null
6463 let identityVerifiedAt : Date | null = null ;
65- let veriffIdentityHash : string | null | undefined = undefined ;
6664
6765 let { sessionUrl, attemptCount, declineReason, sessionExpiresAt } =
6866 parseVeriffMetadata ( partner . veriffMetadata ) ;
@@ -72,19 +70,19 @@ export const handleDecisionEvent = async ({
7270
7371 // If the verification was approved, check for country mismatch
7472 if ( effectiveStatus === "approved" ) {
75- veriffIdentityHash = computeVeriffIdentityHash ( verification ) ;
76- const isDuplicate = await checkDuplicateIdentity ( {
77- partner ,
78- veriffIdentityHash ,
79- riskLabels ,
80- } ) ;
73+ const hasDuplicateRiskLabel =
74+ riskLabels &&
75+ riskLabels ?. length > 0 &&
76+ riskLabels . some ( ( { label } ) =>
77+ veriffRiskLabels . includes ( label as VeriffRiskLabel ) ,
78+ ) ;
8179
8280 const isCountryMismatch = checkCountryMismatch ( {
8381 partner,
8482 verification,
8583 } ) ;
8684
87- if ( isDuplicate ) {
85+ if ( hasDuplicateRiskLabel ) {
8886 effectiveStatus = "declined" ;
8987 declineReason = DUPLICATE_IDENTITY_DECLINE_REASON ;
9088
@@ -124,8 +122,6 @@ export const handleDecisionEvent = async ({
124122 data : {
125123 identityVerificationStatus : veriffStatusMap [ effectiveStatus ] ,
126124 identityVerifiedAt,
127- veriffIdentityHash :
128- effectiveStatus === "approved" ? veriffIdentityHash : null ,
129125 veriffMetadata,
130126 } ,
131127 select : {
@@ -163,46 +159,6 @@ function checkCountryMismatch({
163159 return partner . country . toUpperCase ( ) !== veriffCountry ;
164160}
165161
166- async function checkDuplicateIdentity ( {
167- partner,
168- veriffIdentityHash,
169- riskLabels,
170- } : {
171- partner : Pick < Partner , "id" > ;
172- veriffIdentityHash : string | null ;
173- riskLabels : VeriffDecisionEvent [ "verification" ] [ "riskLabels" ] ;
174- } ) : Promise < boolean > {
175- if ( ! veriffIdentityHash && ( ! riskLabels || riskLabels . length === 0 ) ) {
176- return false ;
177- }
178-
179- const hasDuplicateRiskLabel =
180- riskLabels &&
181- riskLabels ?. length > 0 &&
182- riskLabels . some ( ( { label } ) =>
183- veriffRiskLabels . includes ( label as VeriffRiskLabel ) ,
184- ) ;
185-
186- if ( hasDuplicateRiskLabel ) {
187- return true ;
188- }
189-
190- if ( veriffIdentityHash ) {
191- const duplicatePartner = await prisma . partner . count ( {
192- where : {
193- veriffIdentityHash,
194- id : {
195- not : partner . id ,
196- } ,
197- } ,
198- } ) ;
199-
200- return Boolean ( duplicatePartner ) ;
201- }
202-
203- return false ;
204- }
205-
206162async function sendEmailNotification ( {
207163 partner,
208164 attemptId,
0 commit comments