How to verify Google reCAPTCHA v3 response

Today we’ll show you how to verify Google reCAPTCHA v3 response using Node.js. In the previous article, we explained to you how to implement reCAPTCHA v3 in React.

Here, we will verify the google reCAPTCHA response using Node.js but you can use any backend technology to verify the response.

Google reCAPTCHA v3

Verify Google reCAPTCHA v3 using Node.js

  1. Create REST API
  2. Enable CORS
  3. Create an API to verify reCAPTCHA v3 response
  4. Output

1. Create REST API

In the first step, we will create a simple REST API with basic configuration. I would recommend you to check the article: Create REST API in Node.js.

Additionally, we will install npm dependencies in the application. Run the following command to install the packages.

After implementing the package, your server code should look like below.

server.js

We’ll use the other plugins for further use.

2. Enable CORS

To enable the CORS, we will use the cors npm package. Refer the following article for more information.

How to enable CORS in Node.js

3. Create an API to verify reCAPTCHA v3 response

Now, we have to create an API to verify reCAPTCHA v3 response. We will use the node-fetch npm package to call an external API. Refer the document for the API request.

We have used the SECRET KEY to verify reCAPTCHA response. Check out the following link to generate keys.

Generate google reCAPTCHA v3 keys

Let’s combine all code together and see how it looks.

server.js

4. Output

To test this API, we recommend you to use the previous article and call \verify API and pass the g-recaptcha-response to verify with google reCAPTCHA backend API.

Output - How to verify Google reCAPTCHA v3 response - Clue Mediator
Output – How to verify Google reCAPTCHA v3 response – Clue Mediator

That’s it for today.
Thank you for reading. Happy Coding..!!

Demo & Source Code

Github Repository

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

4 Responses

  1. Ante says:

    Thank you for a great guide. Simple and it works. A good addition would be a way to remove the Recaptcha badge from the screen for views that don’t use it. For instance, to remove it after user signs in.

  2. John Gabriel says:

    so awesome and helpful

Leave a Reply

Your email address will not be published. Required fields are marked *