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; };