Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: recaptcha added #227

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<your Google Maps JavaScript API Key here>"

NEXT_PUBLIC_SITE_KEY=6LcjyaccAAAAAAjE2z6vBhs2tOdhC-t0F2OCMj7z
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akshitarora921 So let's get this part figured out and we can get this PR in! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Collaborator

@LowLifeArcade LowLifeArcade Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @akshitarora921. So I think what would help a lot is for you to explain what you're doing with these keys.

  • Where are they from
  • What are they doing
  • What we need to do

I've looked into it and it might be better next time for us to get your PR through if you outline what we need to do as a follow up to your work. A list of todos. Here's an example for todos for us:

  • Go to recaptha website and generate keys for production
  • Use sitekey in code (go into detail)
  • Use secret key in server env (go into detail)

This would help a lot.


// Generate these values in the Firebase console:
// PROJECT SETTINGS > Firebase Admin SDK > Generate new private key
Expand Down
14 changes: 14 additions & 0 deletions components/MainDonationForm.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ReCaptchaV2 from 'react-google-recaptcha';
import React from 'react';
import clsx from 'clsx';

Expand Down Expand Up @@ -35,8 +36,10 @@ 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();

console.log(process.env.NEXT_PUBLIC_SITE_KEY);
React.useEffect(() => {
const allSelected = Object.values(selectedCauses).filter(Boolean);
if (allSelected.length === CAUSES.length) {
Expand Down Expand Up @@ -79,6 +82,11 @@ export default function MainDonationForm() {
return;
}

if (reCaptchaToken === '') {
showModal('Please submit the captcha');
return;
}

handleSubmit({ amount, cause });
};

Expand Down Expand Up @@ -115,6 +123,12 @@ export default function MainDonationForm() {
options={AMOUNTS}
value={amount}
/>
<ReCaptchaV2
id="captcha"
onChange={(token) => setReCaptchaToken(token)}
onExpired={() => setReCaptchaToken('')}
sitekey={process.env.NEXT_PUBLIC_SITE_KEY} //need to use env variables process.env.REACT_APP_SITE_KEY
/>
<button
className={clsx('btn btn-primary', { loading: isPending })}
type="submit"
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-google-maps": "^9.4.5",
"react-icons": "^4.3.1",
"react-google-recaptcha": "^2.1.0",
"react-icons": "^4.2.0",
"react-lottie": "^1.2.3",
"stripe": "^8.168.0"
},
Expand Down
35 changes: 29 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,13 @@ hoist-non-react-statics@^2.3.1:
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47"
integrity sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==

hoist-non-react-statics@^3.3.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
dependencies:
react-is "^16.7.0"

hosted-git-info@^2.1.4:
version "2.8.9"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
Expand Down Expand Up @@ -5512,7 +5519,7 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.5"

prop-types@^15.5.8, prop-types@^15.7.2:
prop-types@^15.5.0, prop-types@^15.5.8, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
Expand Down Expand Up @@ -5673,6 +5680,14 @@ [email protected]:
iconv-lite "0.4.24"
unpipe "1.0.0"

react-async-script@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/react-async-script/-/react-async-script-1.2.0.tgz#ab9412a26f0b83f5e2e00de1d2befc9400834b21"
integrity sha512-bCpkbm9JiAuMGhkqoAiC0lLkb40DJ0HOEJIku+9JDjxX3Rcs+ztEOG13wbrOskt3n2DTrjshhaQ/iay+SnGg5Q==
dependencies:
hoist-non-react-statics "^3.3.0"
prop-types "^15.5.0"

react-dom@^17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
Expand All @@ -5699,17 +5714,25 @@ react-google-maps@^9.4.5:
scriptjs "^2.5.8"
warning "^3.0.0"

react-icons@^4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.3.1.tgz#2fa92aebbbc71f43d2db2ed1aed07361124e91ca"
integrity sha512-cB10MXLTs3gVuXimblAdI71jrJx8njrJZmNMEMC+sQu5B/BIOmlsAjskdqpn81y8UBVEGuHODd7/ci5DvoSzTQ==
react-google-recaptcha@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/react-google-recaptcha/-/react-google-recaptcha-2.1.0.tgz#9f6f4954ce49c1dedabc2c532347321d892d0a16"
integrity sha512-K9jr7e0CWFigi8KxC3WPvNqZZ47df2RrMAta6KmRoE4RUi7Ys6NmNjytpXpg4HI/svmQJLKR+PncEPaNJ98DqQ==
dependencies:
prop-types "^15.5.0"
react-async-script "^1.1.1"

react-icons@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.2.0.tgz#6dda80c8a8f338ff96a1851424d63083282630d0"
integrity sha512-rmzEDFt+AVXRzD7zDE21gcxyBizD/3NqjbX6cmViAgdqfJ2UiLer8927/QhhrXQV7dEj/1EGuOTPp7JnLYVJKQ==

[email protected], "react-is@^16.12.0 || ^17.0.0", react-is@^17.0.1, react-is@^17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==

react-is@^16.8.1:
react-is@^16.7.0, react-is@^16.8.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
Expand Down