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:

Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 ⋅ 7 min read
Implementing Infinite Scroll In Next Js With Server Actions

Implementing infinite scroll in Next.js with Server Actions

Infinite scrolling in Next.js no longer requires external libraries — Server Actions let us fetch initial data directly on the server.

Rahul Chhodde
Apr 19, 2024 ⋅ 10 min read
Integrating Django Templates With React For Dynamic Webpages

Integrating Django templates with React for dynamic webpages

Create a dynamic demo blog site using Django and React to demonstrate Django’s server-side functionalities and React’s interactive UI.

Kayode Adeniyi
Apr 18, 2024 ⋅ 7 min read
Using Aoi Js To Build A Bot For Discord

Using aoi.js to build a bot on Discord

Explore how the aoi.js library makes it easy to create Discord bots with useful functionalities for frontend applications.

Rahul Padalkar
Apr 17, 2024 ⋅ 9 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