From 6f3d5ac54b792c155606c162ef3f4eecfa089726 Mon Sep 17 00:00:00 2001 From: Akshit Arora Date: Sun, 3 Oct 2021 23:29:48 +0530 Subject: [PATCH 1/3] recaptcha added --- .env.example | 2 +- components/MainDonationForm.js | 13 +++++++++++++ package.json | 1 + yarn.lock | 27 +++++++++++++++++++++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 89a9628a..a6fbf6ef 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ STRIPE_SECRET_KEY = "sk_test_51JJ3vNLOlCyqSHKrp2vu93c9YzrXxDq7otphDYZqQTE10eZ0Gs CANCEL_URL = "https://helpafamily.margaritahumanitarian.org/" SUCCESS_URL = "https://helpafamily.margaritahumanitarian.org/thank-you" NEXT_PUBLIC_GMAPS_JS_API_KEY = "" - +REACT_APP_SITE_KEY='6LeSv6ccAAAAAGL98cTakxdX_lvAUe-D3SR06bXw' // Generate these values in the Firebase console: // PROJECT SETTINGS > Firebase Admin SDK > Generate new private key diff --git a/components/MainDonationForm.js b/components/MainDonationForm.js index bb0b8a8c..1823eb0b 100644 --- a/components/MainDonationForm.js +++ b/components/MainDonationForm.js @@ -1,3 +1,4 @@ +import ReCaptchaV2 from 'react-google-recaptcha'; import React from 'react'; import clsx from 'clsx'; @@ -35,6 +36,7 @@ export default function MainDonationForm() { const [selectedCauses, setSelectedCauses] = React.useState({}); const [isAnyoneInNeed, setIsAnyoneInNeed] = React.useState(true); const [cause, setCause] = React.useState(''); + const [reCaptchaToken, setReCaptchaToken] = React.useState(''); const [handleSubmit, isPending] = useStripeSession(); React.useEffect(() => { @@ -79,6 +81,11 @@ export default function MainDonationForm() { return; } + if (reCaptchaToken === '') { + showModal('Please submit the captcha'); + return; + } + handleSubmit({ amount, cause }); }; @@ -115,6 +122,12 @@ export default function MainDonationForm() { options={AMOUNTS} value={amount} /> + setReCaptchaToken(token)} + onExpired={() => setReCaptchaToken('')} + sitekey={'6LcjyaccAAAAAAjE2z6vBhs2tOdhC-t0F2OCMj7z'} //need to use env variables process.env.REACT_APP_SITE_KEY + />