From 3b2ef5bb1bdc826c7ccd0da5df754bf2056f3c0f Mon Sep 17 00:00:00 2001 From: Christian Lewis <1657236+ctjlewis@users.noreply.github.com> Date: Thu, 13 May 2021 21:48:04 -0500 Subject: [PATCH] chore: clarify CAPTCHA logic --- .../VerifyAuthChallengeResponse/captcha-verify.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/amplify-category-auth/provider-utils/awscloudformation/triggers/VerifyAuthChallengeResponse/captcha-verify.js b/packages/amplify-category-auth/provider-utils/awscloudformation/triggers/VerifyAuthChallengeResponse/captcha-verify.js index 1bb2f057d17..6df533d31e7 100644 --- a/packages/amplify-category-auth/provider-utils/awscloudformation/triggers/VerifyAuthChallengeResponse/captcha-verify.js +++ b/packages/amplify-category-auth/provider-utils/awscloudformation/triggers/VerifyAuthChallengeResponse/captcha-verify.js @@ -7,11 +7,16 @@ exports.handler = async (event, context, callback) => { `https://www.google.com/recaptcha/api/siteverify?secret=${process.env.RECAPTCHASECRET}&response=${event.request.challengeAnswer}`, {}, ); - - if (!(response && response.data && response.data.success)) { + /** + * If the CAPTCHA challenge succeeded, set the `answerCorrect` field to + * `true`; otherwise, set it to `false` and throw an error. + */ + const challengeSucceeded = response && response.data && response.data.success; + if (challengeSucceeded) { + event.response.answerCorrect = true; + } else { event.response.answerCorrect = false; - throw new Error('captcha verification error'); + throw new Error('CAPTCHA verification error'); } - return event; };