Skip to content

Commit a819fc4

Browse files
authored
Merge pull request #166 from IABTechLab/kcc-UID2-6512-fix-crashing-error
Check token empty before making the API call
2 parents 69d52a4 + 83988fe commit a819fc4

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const EmailPromptRequest = z.object({
5252
email: z.string(),
5353
countryCode: z.string().optional(),
5454
phone: z.string().optional(),
55-
recaptcha: z.string(),
55+
recaptcha: z.string().min(1, 'reCAPTCHA token is required'),
5656
idType: z.string().optional(),
5757
});
5858

src/routes/recaptcha.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const SCORE_THRESHOLD = 0.5;
77

88
export default async function createAssessment(token: string, recaptchaAction: string, traceId: TraceId, userIpAddress?: string) {
99
const { errorLogger } = getLoggers();
10+
11+
// Validate token before making the API call
12+
if (!token || token.trim() === '') {
13+
errorLogger.error('reCAPTCHA token is empty or missing', traceId);
14+
return null;
15+
}
16+
1017
const projectId = RECAPTCHA_PROJECT_ID;
1118
const client = new RecaptchaEnterpriseServiceClient();
1219
const projectPath = client.projectPath(projectId);

0 commit comments

Comments
 (0)