Skip to content

Commit

Permalink
chore: clarify CAPTCHA logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ctjlewis committed May 14, 2021
1 parent 0d67043 commit 3b2ef5b
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 3b2ef5b

Please sign in to comment.