2022-06-09
3167
#react
David Omotayo
115071
Jun 9, 2022 ⋅ 11 min read

How to implement reCAPTCHA in a React application

David Omotayo Frontend developer and indie game enthusiast.

Recent posts:

TypeScript logo over a pink and white background.

Drizzle vs. Prisma: Which ORM is best for your project?

Compare Prisma and Drizzle ORMs to learn their differences, strengths, and weaknesses for data access and migrations.

Temitope Oyedele
Nov 21, 2024 ⋅ 10 min read
Practical Implementation Of The Rule Of Least Power For Developers

Practical implementation of the Rule of Least Power for developers

It’s easy for devs to default to JavaScript to fix every problem. Let’s use the RoLP to find simpler alternatives with HTML and CSS.

Timonwa Akintokun
Nov 21, 2024 ⋅ 8 min read
Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 ⋅ 4 min read
Robot pretending to be a person.

Using curl-impersonate in Node.js to avoid blocks

Bypass anti-bot measures in Node.js with curl-impersonate. Learn how it mimics browsers to overcome bot detection for web scraping.

Antonello Zanini
Nov 20, 2024 ⋅ 13 min read
View all posts

13 Replies to "How to implement reCAPTCHA in a React application"

  1. Great post. I ran into some trouble after naming my component in lower case and React wasnt reconizing it as a component until i changed it lo upper case.

  2. Thank you, Mark. React components always start with uppercase letters. The library treats any component with lowercase initials as HTML elements.

    1. Hi Rasam, you have to perform a conditional check based on the response you get from the server. If it’s positive, submit the form. If not, do otherwise. I hope this helps.

      1. Something’s wrong with the backend here – the form does not verify the secret key or token and always shows that its human – regardless if you click the checkbox or not

        1. Hi Laura, I would like to express my apologies for any inconvenience you may have experienced. The handling of the Google API response was not executed correctly. However, I have rectified the issue and I hope you can continue with your work without any further issues. happy hacking!

  3. Using nodejs for the captcha verification process is totally unnecessary.
    Just use const [isVerified, setVerified] = useState(false);

    And create an onChange handler and add it to your recaptcha component
    All the onChange handler has to do is check for a token and if there is a token set “isVerified” to true

    1. This approach of yours only checks for a token. Node.js is for verifying the generated token with Google’s API.

  4. Does anyone know how the ‘reaptcha’ library works? I’ve looked through their example code but I can’t see where they’re verifying the captcha with Google’s servers.

    And if they are handling verification with Google, how are they doing it without the secret key? AFAIK and according to this article, it’s essential to the verification process.

  5. Thanks for this tutorial. It seems that this tutorial has some errors:
    – For the server, the `npm i` command should also include `cors` (besides `express`, `axios`, `dotenv`)
    – In the updated `handleSubmit` function that makes the request to the server, the `axios.post` call should take the arguments `(“http://localhost:2000/post”, { inputVal, token })`, instead of `(inputVal, token)`

Leave a Reply